iPhone, Where do I have to save user generated files if I want them to stay there after an app Upgrade (new release)? is Documents directory good? - iphone

I have an app that lets user record their own audio.
By now I'm saving those files into Documents directory.
My question is: if I will release a new version of that app, will user recorded files get deleted?
Is there a better place to store user generated audio files?
Should I use NSUserDefaults for data that stay even after app upgrade?
thx

NSUserDefaults is used for storing settings (objects of Key-Value Coding compliant classes)
Other data such files you should store in Documents folder, wich survive between updates (if you don't delete it yourself, of course :)

Both the Documents directory and NSUserDefaults survive application updates. Choosing which to use depends on the kind of your data.

if I will release a new version of that app, will user recorded files get deleted?
No.
Is there a better place to store user generated audio files?
No.
Should I use NSUserDefaults for data that stay even after app upgrade?
Only if your data is small.

Related

ALAssetURL unique even after SYNC ipad/iPhone with iTunes

The documentation describes it as 'persistent' (http://developer.apple.com/library/ios/documentation/AssetsLibrary/Reference/ALAssetRepresentation_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40009728-CH1-SW16) but does this mean persistent over a single sync, persistent until new photos are added, persistent until old photos are deleted, or what? If I build a database that associates photo elements in the Camera Roll/Photo Library to data in my application using their ALAssetRepresentation url's, will these associations continue to work forever, even if the photos are moved or renamed?
If Asset url are not unique after sync then what is the alternate solution for this as i need to identify assets uniquely even after sync.
In my experience, the URLs are persistent between syncs (starting in iOS 5). But once the device is restored from an iTunes backup or from iCloud, the assets will get new URLs. This also happened after the upgrade from iOS 5 to iOS 6.
The alternative would to generate an own ID/Checksum for every photo: e.g. take the filename, recording date and file size and generate an MD5 or SHA1 Hash from it.

What happens to the content in my app after i upgrade/update the version in iPad/iPhone

I am storing a lot of images, books, audios etc of my app in
Documents Directory/Library/caches folder.
What happens to all the content if the user updates the version of the app from the app store or from iTunes. Will all of them get erased or will they be untouched during the app updating process?
They will be untouched during the upgrade process. I would like to note however that the Caches folder is meant to be used for data that is just cached rather than data you expect to always be available. The OS reserves the right to get rid of anything in the caches folder. If you're asking this question then I assume you want the data to be persistent so you should be aware that since iOS 5, Apple specifically state that data in the caches directory can be deleted at any time (apart from whilst your app is running).
They are supposed to remain untouched. There are a lot of existing examples for this behavior - try checking any photo sharing application or games that download levels in-game.

Are NSUserDefaults data synced to iTunes?

I understand that NSUserDefaults data is unencrypted and should not be used to store sensitive information. I'm trying to understand how easily someone could get at that information. This thread shows that it's just a plain file on the iphone filesystem.
Will this file be transferred to the user's computer during an iPhone sync (if app sync is enabled)? If so, then it'd be extremely easy for anyone to read information stored in NSUserDefaults
Yes the file will be synced during a backup and it will be just a regular file unless the user has enabled encrypted backups in iTunes, in which case the entire backup contents are encrypted.
I tried this out. Turns out that it's not the same plist file that you can see in the simulator, but it is there in the backup directory after a sync. You can see the contents by running strings.
All the more reason to use the keychain!

iPhone when does data get restored from backup

When does data get restored for an app? What if I save data in the app's document directory. Then they sync with iTunes. Now iTunes has a backup. Will that data be populated to another device when they sync that new device to their iTunes or will they just get a clean install of my app? I'm trying to figure out how to keep track of a subscription in app purchase and was wondering if I could keep record in NSUserDefaults or some other local store.
Backups are per-device. So a backup of your iPod will not be restored to your iPhone. In other words, there is no sync.
Many times iTunes fails to create complete backup of all the iPhone data say it be contacts, message, mails etc. This type of problem may occur due to not installing iTunes properly. So, you should check whether iTunes have been installed correctly or not. In case there is no problem with iTunes then it is possible that you are trying to create backup of the files which can not be backed with the help of iTunes. To overcome with this issue you need to make use of iPhone backup application. By using this tool you will be able to prepare backup of all the files within minutes safely.
If the user backs up to iTunes, and then restores their backup to another device (maybe they lost their original iPhone), the contents of the app Documents directory will be put on the new device. Anything in the tmp folder won't be backed up or restored like this, but the Documents folder will.
However, that's not the best way to store the in-app purchase information. You should be storing that on your own server and keeping a count of the number of times the purchased content has been used. Inform the user that they can use it a certain number of times (say three) and after that they will have to buy it again. I'm not exactly sure of any details beyond that (like how to verify their identity) but it should get you started.

Writing to SQLite3 on iPhone simulation

I have an app that is running in the simulator. I read and write from a sqlite3 data source. However, if i restart the app, then all datg that i had previously wrote to the db is lost.
The data is always in its original state.
Now back when i was developing this app i thought i read somewhere that data can not be persisted via iphone simulator.
Can anybody confirm or deny this?
Thanks!
You need to place your db file in a writable place, e.g. in the Documents folder. All the bundle files are read-only files.
If you are distributing an initial database with the app, you will need to copy it to Documents (or another folder) and use the copy.
You also need to ensure that you close the database connection in your application is closing (i.e. you receive a applicationWillTerminate message).