Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Saving data to disk on iOS

My application got rejected for following reason:

App Review
1.0 Binary Rejected August 5, 2015
2.23 Details On launch and content download, your app stores 9.51 MB on the user's iCloud, which does not comply with the iOS Data Storage

As much as I understand (correct me if I'm wrong) it's because I save too much on NSUserDefaults(I don't save anywhere else).

So here's my question: Is there a quick, easy way to save data locally(similiar to NSUserDefaults but not end up saving on "user's iCloud", instead of using CoreData?

like image 491
Eilon Avatar asked Jul 22 '26 04:07

Eilon


1 Answers

Yes, there is a way. You can store your data using NSKeyedArchiver and NSKeyedUnarchiver. NSKeyedArchiver is used to save your data. An example:

[NSKeyedArchiver archiveRootObject:counters toFile:filePath];

Extension of the filePath should be .plist; counters in this case is an array.

NSKeyedUnarchiver is used to load your data. An example:

if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
    counters = [NSKeyedUnarchiver unarchiveObjectWithFile:filePath];
}

If you want to store your custom class, you need to implement NSCoding protocol.

like image 169
Randex Avatar answered Jul 24 '26 19:07

Randex



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!