Prevent NSUserDefaults from iCloud Backup

There are three ways I am aware of permanently recording to a device in iOS:

  • NSUserDefaults
  • Custom Objects - Archived and written in PATH in NSDocuments
  • SQLite

Apple provides mechanism to prevent iCloud backups C # 2 ie

- (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL

I'm using NSUserDefaults to store three images, but I'm sticking to iOS data storage guidelines - How do I prevent iCloud backup with NSUserDefaults?

This question has been asked several times on SO but there is no clear definitive answer yet.

Is there such a function or do I need to change the saving of images using method # 2. I was hoping for something convenient like:

- (BOOL)addSkipBackAttributeForStandardUserDefaultsKey:(NSString *)

      

exist.

+3


source to share


1 answer


There is no mechanism for this. NSUserDefaults

not intended to store application data. It is there to hold user preferences and other settings that applications require, but not intended as a complete data storage system.

It is incorrect to say that this "[Apple] storage mechanism cannot follow its own rules" because that is not the purpose of this API. In this case, in particular, if these images are not to be copied, then absolute proof that the custom default settings are the wrong place to store them.



You must save images to files. If you have it UIImage

, it's simple. UIImage

matches NSCoding

, so it's easy to convert to / from NSData

. And NSData

includes methods to read / write objects to files. If the filenames may change, you can reasonably put the filenames in the user's default settings. If the filenames are known in advance and cannot be changed, then there is no reason to keep them.

+6


source







All Articles