美文网首页
IOS 审核 屏蔽Documents目录自动备份到iCloud

IOS 审核 屏蔽Documents目录自动备份到iCloud

作者: jksniper | 来源:发表于2019-04-02 16:58 被阅读0次

IOS 审核 屏蔽Documents目录自动备份到iCloud

//在didFinishLaunchingWithOptions函数后调用addNotBackUpiCloud即可屏蔽documents下所有文件自动备份到iCloud.
- (void)addNotBackUpiCloud{
    NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
    NSString* docPath = [documentPaths objectAtIndex:0];
    [self addSkipBackupAttributeToItemAtURL:docPath];
}

/**
 *屏蔽ios文件不备份到icloud
 */
- (BOOL)addSkipBackupAttributeToItemAtURL:(NSString *)filePathString{
    NSURL* URL = [NSURL fileURLWithPath:filePathString];
    assert([[NSFileManager defaultManager] fileExistsAtPath:[URL path]]);
    NSError *error = nil;
    BOOL success = [URL setResourceValue:[NSNumber numberWithBool:YES]
                                  forKey:NSURLIsExcludedFromBackupKey error:&error];
    if(!success){
        NSLog(@"Error excluding %@ from backup %@", [URL lastPathComponent], error);
    }
    return success;
}

相关文章

网友评论

      本文标题:IOS 审核 屏蔽Documents目录自动备份到iCloud

      本文链接:https://www.haomeiwen.com/subject/pbggbqtx.html