Resolved Setting NSDocumentDirectory so it doesn't backup to iCloud

Discussion in 'iOS Programming' started by troop231, Aug 24, 2012.

  1. troop231, Aug 24, 2012
    Last edited: Aug 24, 2012

    troop231 macrumors 603

    Jan 20, 2010
    Hello, I'm trying to mark the entire folder of my app's NSDocumentDirectory so that it is excluded from the iCloud backup, but when I go to the terminal and run: xattr -plxv <file name goes here> I get this error: No such xattr:

    Here is the code I'm using:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documentsDirectory = [paths objectAtIndex:0];
        NSURL *pathURL= [NSURL fileURLWithPath:documentsDirectory];
        [self addSkipBackupAttributeToItemAtURL:pathURL];
    - (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL
        if (&NSURLIsExcludedFromBackupKey == nil) { // iOS <= 5.0.1
            const char* filePath = [[URL path] fileSystemRepresentation];
            const char* attrName = "";
            u_int8_t attrValue = 1;
            int result = setxattr(filePath, attrName, &attrValue, sizeof(attrValue), 0, 0);
            return result == 0;
        } else { // iOS >= 5.1
            NSLog(@"%d",[URL setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:nil]);
            return [URL setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:nil];
    I appreciate any help offered.
  2. chown33 macrumors 604

    Aug 9, 2009
    I suggest starting with a simple listing of all xattrs on the target file. This is a basic debugging principle: start broadly and narrow it down with evidence. If you start broadly by listing all xattrs, you can then proceed to narrow it down to a specific xattr's value. The key point is to get the initial evidence of ALL xattrs, instead of assuming one.

    If the target file has no xattrs, then change your code to show the actual pathname, because the real pathname might not be what you expect. Confirm your expectations by getting evidence (another basic debugging principle).
  3. troop231 thread starter macrumors 603

    Jan 20, 2010
    These are all the xattr's that are on the file:
  4. chown33 macrumors 604

    Aug 9, 2009
    What pathname did you use in the xattr command-line?

    What is the actual pathname used when the code runs?

    What is the actual value being returned by addSkipBackupAttributeToItemAtURL? You go to some trouble to return a success/fail indicator, then you never check it. That's another elementary debugging principle: checking for errors instead of ignoring them.

    What is the NSLog output when the code runs? I.e. what's the evidence that the sextattr() is being performed, vs. the setResourceValue:? You may think setResourceValue: does the same thing as setxattr(), but what's your evidence?

Share This Page