Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Core Data "do not backup" flag

Tags:

ios

core-data

My app has a core data db that is filled upon the first launch for offline use. This db is then synced in every launch with an online db. Only the first launch contains a significant amount of data. The app also fetches some images from the web, which are then converted to binary data and saved to core data for offline use. This only happens when the user navigates to a section containing some images, and only those images are fetched ( the app does not fetches all images at once, only as they are needed).

I am using Magical Record.

I do not save any kind of data to file at runtime. However my app got rejected with this message:

We found that your app does not follow the iOS Data Storage Guidelines, which is required per the App Store Review Guidelines.

It advises me to check "Settings > iCloud > Storage & Backup > Manage Storage " but my app does not even shows.

I understand I should mark core data not to bakcup to iCloud, but I do not understand how to do this. Supposedly I should implement something like this, but do not know how to apply it to my core data files.

- (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL {
assert([[NSFileManager defaultManager] fileExistsAtPath: [URL path]]);

NSError *error = nil;
BOOL success = [URL setResourceValue: [NSNumber numberWithBool: YES]
                              forKey: NSURLIsExcludedFromBackupKey error: &error];
if(!success){
    NSLog(@"Error excluding %@ from backup %@", [URL lastPathComponent], error);
}
return success; }
like image 455
JoaoFLF Avatar asked Oct 22 '22 19:10

JoaoFLF


1 Answers

Below may be better than changing MacigalRecord's source files. In swift

MagicalRecord.setupCoreDataStackWithAutoMigratingSqliteStoreNamed("somedb.sqlite")
let dbPath = NSPersistentStore.MR_urlForStoreName("somedb.sqlite")
do {
  try dbPath.setResourceValue(NSNumber(bool: true), forKey: NSURLIsExcludedFromBackupKey)
} catch let error {
    print(error)
}
like image 55
e-zuka Avatar answered Oct 27 '22 08:10

e-zuka