Search code examples
iosnsurl

How to know if NSURLIsExcludedFromBackupKey is working?


I recently had my app rejected due to:

2.23: Apps must follow the iOS Data Storage Guidelines or they will be rejected

The reason for this is my app downloads a lot of image files from the web and writes them to the documents directory. So I do the following to try and remedy the situation:

    NSURL *url = [NSURL URLWithString:stickerURL];
    NSError *error = nil;
    BOOL success = [url setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:&error];

    if(!success)
    {
        NSLog(@"Error excluding %@ from backup %@", [url lastPathComponent], error);
    }

    NSData *data = [NSData dataWithContentsOfURL:url];

My question is, how am I to know if NSURLIsExcludedFromBackupKey is working? The BOOL success is always coming back as YES. However, when I check Settings -> iCloud -> Storage & Backup -> Manage Storage -> MyiPhone5, it's making no difference in the size that is being shown underneath my app. Would this mean it's not working? If not, what can I fix in my code?


Solution

  • If you are checking "Manage Storage" in your device's settings, and after adding a bunch of files (eg., photos, documents, or whatever it is you're flagging to not be backed up) you notice that the backup size for you app is increasing, then the flag isn't "working" (although that shouldn't be the case, really).

    One way to test it is to get rid of the key NSURLIsExcludedFromBackupKey, download a bunch of data, and then check to see if the backup size is increasing. Then, once you add the key back into your code, and once again download a bunch of data, the backup storage size should really not increase noticeably.