1

I use NSUserDefaults to store image data by encoding. I know it can be saved in the Documents directory, but this will lead to App Store rejection because of the iCloud sync issue if the content is too great. It could also be saved in the Cache directory but the images I save are very important and I don't want to lose them upon cache clearance.

I'm concerned my app will be rejected due to such heavy use of NSUserDefaults for data storage -- is there any other way of handling this within the offline context?

jscs
  • 63,694
  • 13
  • 151
  • 195
Dilshan
  • 3,231
  • 4
  • 39
  • 50

3 Answers3

4

NSUserDefaults is not appropriate for storing images. You should store these under ~/Library/Application Support. Since you're saying you don't want them to be backed-up, you should follow the instructions from the iOS App Programming Guide:

In iOS 5.1 and later, store support files in the /Library/Application Support directory and add the NSURLIsExcludedFromBackupKey attribute to the corresponding NSURL object using the setResourceValue:forKey:error: method. (If you are using Core Foundation, add the kCFURLIsExcludedFromBackupKey key to your CFURLRef object using the CFURLSetResourcePropertyForKey function.) Applying this attribute prevents the files from being backed up to iTunes or iCloud. If you have a large number of support files, you may store them in a custom subdirectory and apply the extended attribute to just the directory.

Rob Napier
  • 286,113
  • 34
  • 456
  • 610
2

I can't say about rejection but NSUserDefaults is almost certainly wrong for this. (It's meant for User Preference data.)

I'd suggest you look into Core Data.

Here's a recent argument suggesting the same: http://sealedabstract.com/code/you-should-use-core-data/

Cool quote from it:

if you are saving more than 3 objects to disk without linking to CoreData.framework, you’re doing it wrong.

Hope that helps.

Carlton Gibson
  • 7,278
  • 2
  • 36
  • 46
0

The accepted answer to this question might be helpful.

The main point given, for your question:

Put files in Documents but flag them so that they are not backed up. There's a technote (QA1719) on how to do this.

Community
  • 1
  • 1
Hjalmar
  • 989
  • 8
  • 16