It's difficult to find explicit info on this.
Let's say I have something stored in NSUserDefaults and I do not want it to sync with iTunes. Should it be stored in the keychain instead? Does the keychain sync?
Instead of messing with the device keychain (whose elements don't get deleted on app removal) you can simply use an NSMutableDictionary and mix it with initWithContentsOfFile:, writeToFile:atomically: and the kCFURLIsExcludedFromBackupKey, this way you would have exactly the same structure of the NSUserDefaults (that is no other that a NSMutableDictionary at its heart) and you have control over if it should backed up or not. Mind that #rmaddy suggestion of putting it in the cache directory means that, if the device needs memory, your file would be wiped.
EDIT: Sorry probably I misread, the kCFURLIsExcludedFromBackupKey is to not have it synced from iCloud not iTunes. If you simply want to not be syncd with iTunes you can set the UIFileSharingEnabled to NO in your app's plist
EDIT2: According to the documentation (section Where You Should Put Your App’s Files) the kCFURLIsExcludedFromBackupKey will exclude it to be backed up by iTunes too.
Related
Users have reported that, when they restore a device from an iCloud (as opposed to an iTunes) backup, the data for my app is not restored. It is not clear to me the steps I need to take to ensure that my app data is restored when the entire device is restored from an iCloud backup.
I do not have iCloud enabled in app capabilities; is this one of the steps I need to take to make sure my data is included in the restore? What are the other steps I need to take and things I need to check?
More info:
I have a Core Data app and store a .sqlite file. I store my file in [[UIApplication sharedDelegate] applicationDocumentsDirectory]. I use NSUserDefaults. My app doesn't appear in any list for iCloud within Settings.
You do not have to include iCloud capabilities. iCloud backs up automatically what is saved into DocumentsDirectory and also saves NSUserDefaults.
Bear in mind that for those datas you don't want to be included in iCloud, you must add - (BOOL)addSkipBackupAttributeToItemAtPath:(NSString *) filePathString flag. Apple is very strict with this backup and you must save only user-generated content, or else app will be rejected.
Important: Apps should avoid mingling app data and user data in the
same file. Doing so will unnecessarily increase backup sizes and can
be considered a violation of the iOS Data Storage Guidelines.
To check how much space your app use in iCloud Backup (and figure out if your data is saved or not) you can check here:
- Install and launch your app
- Go to Settings > iCloud > Storage > Manage Storage
- Select your device
- If necessary, tap "Show all apps"
- Check your app's storage
If you know your app should store bigger data you will see there but please note that what is under 100-150kb is from NSUserDefaults
Let me know if you have more questions.
I'm developing an iOS app that has to support iOS 5+. I've read the iOS Data Storage Guidelines in order to prepare the app for the submission and read several questions and solutions about those guidelines here in Stackoverflow, but I still have some doubts about how I should handle this.
I have an sqlite database whose tables are defined in an .sqlite file. I copy this file into \Documents folder when app starts, and I keep such file always there in \Documents. This database firstly contains some collections of fixed data that app may need (lists of cities to select and things like that), and the rest is user-dependent data that will be downloaded. I've read this post: Apps must follow the iOS Data Storage Guidelines or they will be rejected in app that contains .sqlite3, but I still don't know what criteria should I apply. The .sqlite is not downloadable, it is included in Supported Files of the Xcode project, and some of the initial data is inserted from inside the app and it is neither downloadable. The user-dependent data, well, I can download it whenever I need. I've not integrated any iCloud stuff in my app. So, should it be correct to keep the .sqlite file always in Documents? AFAIK, you need the file to be there for performing all database operations...
As I said, I've not included any iCloud related code in my app, and in fact I don´t know how iCloud is managed because I've never told to do it, are backups of the app made anyway? Should I use the flags the iOS Data Storage Guidelines says in order to prevent files to be backuped? I need some guidence regarding backups and iCloud considerations.
And there is another thing: my app also downloads some user-dependent images. I show them in several views throughout the app, so I need them to persist while the normal working of the app. However, it is downloadable content. So, where should I place them?
Thanks a lot!
I believe your .sqlite file should be in Documents, this is the correct place for it.
You downloaded images should probably be in Caches, but you could also get away with them in documents as long as you set the "do not backup" attribute.
You can set the skip backup attribute like this:
BOOL success = [url setResourceValue: [NSNumber numberWithBool: skip]
forKey: NSURLIsExcludedFromBackupKey error: &error];
I have some problems because of iCloud and i want to turn off its for my app,how can i do it in the code of my application,i thought about my problem and the decision can be turning off the iCloud, thanks for help
If you store files in Documents, they will be backed up to iCloud automatically. If you don't want that, the easiest way is to just store them somewhere else. Library/Caches is a good choice. If you really MUST store in Documents but you want to disable iCloud backup you can use the technique outlined here:
https://developer.apple.com/library/ios/#qa/qa1719/_index.html
I'm having some trouble getting an app accepted into the App Store. The problem is that the database is getting backed up to the iCloud, according to Apple, although I attempted to prevent that by setting the skipBackupFlag for the database file to YES per Apples documantation.
I may have done something wrong, so I'd like to check that before resubmitting the app. Note that I'm storing the DB in the NSLibrary directory with my bundle's identifier appended as a subdirectory, so the actual directory is this:
/var/mobile/Applications/DA9AF74B-3735-4325-BE87-F4D3003AD205/Library/com.mycompany.myapp/my.db:
As a check, on my iPod I went to "settings", "iCloud storage and backup", "Manage Storage", "show all apps", but my app is showing up as only 1.3 kb. According to Apple, it's backing more than 7mb to iCloud, so for them the backup is including the database file.
One additional question (if I'm unable to figure out how to test the skipBackupFlag) - is it sufficient to just set the database file's skipBackupFlag to YES, or should the directory's skipBackupFlag also be set?
I never did figure out how to test the skipBackupFlag, but I'm pretty sure I was setting it incorrectly. Once I patched that, the app was accepted. The data's not getting backed up, and it's stored in NSDirectory.
I was wondering if it was possible to use iCloud to sync an app's preferences file between devices. The preference file I am talking about is the com.domain.appname.plist file created by NSUserDafults to store the app's preferences.
I would like to have the option of keeping my app's preferences file in sync between two different devices (an iPad and an iPhone, for example). Is this an acceptable use of iCloud syncing? Or would I need to convert the plist file into a different type of document, store it on the cloud, and convert it back into the app's preferences file upon retrieving it?
thanks!
Similar to MKiCloudSync, I also have a library on GitHub called SDCloudDefaults. Rather than sync automatically, there's a new object that you use instead of NSUserDefaults that saves to both iCloud and NSUserDefaults. This means you can decide which elements are stored locally and which are stored in the cloud.
(I found MKiCloudSync after I'd implemented it. I think it's clever but I don't want to sync everything to iCloud so my solution still works better for me.)
There is a library available to do this with one line of code
https://github.com/MugunthKumar/MKiCloudSync
It is possible to sync preferences between devices using iCloud. However, I would recommend against sharing the plist file between devices.
The NSUbiquitousKeyValueStore should be suitable for what you trying to do. It is very similar to NSUserDefaults, so it should be easy to pick up.
To use it, simply enable the com.apple.developer.ubiquity-kvstore-identifier entitlement in your entitlements file and just duplicate the preferences you like to sync in the ubiquitous key value store. Once it's in the ubiquitous kvstore, you'll be able to see it from the application on other devices. You can even sync between different applications as long as they use the same identifier.
You should also register for the NSUbiquitousKeyValueStoreDidChangeExternallyNotification notification to watch for new changes and update the standardUserDefaults on the device accordingly.