0

Currently I have a method that looks like this to prevent a file from being backed up by iCloud:

- (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL
{
    const char* filePath = [[URL path] fileSystemRepresentation];
    const char* attrName = "com.apple.MobileBackup";
    if (&NSURLIsExcludedFromBackupKey == nil) {
        // iOS 5.0.1 and lower
        u_int8_t attrValue = 1;
        int result = setxattr(filePath, attrName, &attrValue, sizeof(attrValue), 0, 0);
        return result == 0;
    }
    else {
        // First try and remove the extended attribute if it is present
        int result = getxattr(filePath, attrName, NULL, sizeof(u_int8_t), 0, 0);
        if (result != -1) {
            // The attribute exists, we need to remove it
            int removeResult = removexattr(filePath, attrName, 0);
            if (removeResult == 0) {
                NSLog(@"Removed extended attribute on file %@", URL);
            }
        }

        // Set the new key
        return [URL setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:nil];
    }
}

The problem is, is that it uses the iOS 5.1 and above API: NSURLIsExcludedFromBackupKey

The makes it a problem for me while supporting devices under 5.1. Even though the below code says it supports devices under 5.1 it sometimes crashes and is inconsistent.

So, is there any way to prevent files from being backed up by iCloud while not using the NSURLIsExcludedFromBackupKey API?

Thanks!

SimplyKiwi
  • 12,376
  • 22
  • 105
  • 191
  • Did you get this working? I can't get the method for iOS 5.1 working. It doesn't mark the files with the "do not backup" flag. The method for iOS 5.0.1 does works properly, but the one for 5.1 not. – iVela Jun 22 '12 at 20:26
  • No unfortunately. It sets the flag for iOS 5.1 but there is a EXC_BAD_ACCESS crash in here somewhere and thats why I am trying to avoid the NSURLIsExcludedFromBackupKey API. – SimplyKiwi Jun 23 '12 at 16:39

0 Answers0