JoaoFLF
JoaoFLF

Reputation: 91

Core Data "do not backup" flag

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; }

Upvotes: 5

Views: 1370

Answers (2)

e-zuka
e-zuka

Reputation: 121

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)
}

Upvotes: 2

Daniel Amitay
Daniel Amitay

Reputation: 6667

Find: NSPersistentStoreCoordinator+MagicalRecord.m

Then, find:

- (NSPersistentStore *)MR_addSqliteStoreNamed:(id)storeFileName withOptions:(__autoreleasing NSDictionary *)options

At the bottom of the method, you will see:

if (!store) 
{
    [MagicalRecord handleErrors:error];
}

Change that to:

if (!store) 
{
    [MagicalRecord handleErrors:error];
}
else
{
    [self addSkipBackupAttributeToItemAtURL:url];
}

Let me know if the method looks different for you, but this is what I use for my own implementation. Just make sure you drop in the function that you mention in your question.

Upvotes: 1

Related Questions