iOS 5.0.1 : How to verify that the folder is marked as “Do not back up” for iCloud?

不问归期 提交于 2019-11-27 03:41:24

According to the docs you linked, if you set the method up exactly how they have it listed on that page, the method will return YES if the attribute is marked correctly.

Aditya Rathnam

For iOS 5.1, run the app in the simulator, and run the following command in the Terminal:

xattr {filename}

You should see the following if the item is correctly marked for exclusion:

com.apple.metadata:com_apple_backup_excludeItem 
  1. open simulator
  2. delete the app (the app review team runs the code 1 time through, so be sure you are starting from scratch)
  3. now run your code in simulator, your code will store your files on your harddrive.
  4. open up terminal
  5. cd /Users/(user name)/Library/Application Support/iPhone Simulator/(ios version)/Applications
  6. ls
  7. you will be presented with a list of random folder names, open each one until you find your app folder
  8. for file in $(find *); do du -sk $file; xattr -l $file; echo ; done
  9. you will be presented with all of the files in the app in the format of..

    (filesize) (filename)
    (iCloud backup exclusion)

NOTE: if nothing is listed, that means the file will be backed up (if its in the Library or Documents folder).. if instead you see 'com.apple.metadata:com_apple_backup_excludeItem: com.apple.MobileBackup' then you're good to go.

Run the app in the simulator, then use the Terminal to run this command against the relevant files:

xattr -plxv com.apple.MobileBackup <file name>

For iOS 5.1 or later this code works fine for me.

   - (BOOL)addSkipBackupAttributeToItemAtPath:(NSString *)filePathString {
        NSURL *fileURL =
        [NSURL fileURLWithPath:filePathString];

        assert([[NSFileManager defaultManager] 
        fileExistsAtPath: [fileURL path]]);

        NSError *error = nil;

        BOOL success = [fileURL setResourceValue:[NSNumber numberWithBool:YES]
                                      forKey:NSURLIsExcludedFromBackupKey
                                     error:&error];
        return success;
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!