Why can't I save data to my application's bundle when running on the device?

Q:  My application saves data to the application's bundle, which works fine in the iPhone Simulator. However, when I run on a device, my data cannot be saved. What's going on?

A: The different behaviors you are seeing are due to differences between the iPhone Simulator and the actual device. In the simulator, your application bundle is saved in a location that allows you full read/write access, so your code succeeds in writing and saving the preference data to the bundle. However, on the device, your application bundle cannot be modified. The File System Programming Guide contains information on the writeable locations in your application directory.

Your iPhone application's home directory contains a subdirectory for preferences (<Application_Home>/Library/Preferences). However, you should not create preferences files directly, but should instead use the NSUserDefaults or CFPreferences to get and set application preferences.

Alternately, you can save application specific data to the <Application_Home>/Documents subdirectory of your application's home directory. Use the NSFileManager URLsForDirectory:inDomains: method to get a URL to this directory.

Both of the above techniques also have the additional advantage that they will preserve the users data when the application is updated.

 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值