Can I add the Do not Back up for the “Document Directory” for iCloud

前端 未结 4 1788
长情又很酷
长情又很酷 2021-01-07 02:24

I had read that I can mark folders with \"do not backup\" attribute with ios 5.1 and later

As i understand, in such case all contents of directory will be excluded f

4条回答
  •  迷失自我
    2021-01-07 03:14

    Yes you can set the do not backup flag for the folders(file) of Document directory.

    do not backup attribute works on marked files regardless of what directory they are in, including the Documents directory.These files will not be purged and will not be included in the user's iCloud backup. Because these files do use on-device storage space, your app is responsible for monitoring and purging these files periodically.

    for more information for the same go through this link

    Below methods set the Do not back up flag to avoiding the unwanted backup|deletion from the app directory (Document and Cache).just need to call below method and pass url for the Folder(File).

    - (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL {
        if (&NSURLIsExcludedFromBackupKey == nil) { // for iOS <= 5.0.1
            const char* filePath = [[URL path] fileSystemRepresentation];
    
            const char* attrName = "com.apple.MobileBackup";
            u_int8_t attrValue = 1;
    
            int result = setxattr(filePath, attrName, &attrValue, sizeof(attrValue), 0, 0);
            return result == 0;
        } else { // For iOS >= 5.1
            NSError *error = nil;
            [URL setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:&error];
            return error == nil;
        }
    }
    

提交回复
热议问题