Retired Document
Important: This document may not represent best practices for current development. Links to downloads and other resources may no longer be valid.
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.
Document Revision History
Date | Notes |
---|---|
2012-11-06 | Editorial |
2009-08-25 | New document that describes why you can't save data to your application's bundle when running on the device. |
Copyright © 2012 Apple Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2012-11-06