停止iCloud备份

时间:2016-05-13 07:00:00

标签: ios objective-c sqlite icloud icloud-drive

我是iOS开发的新手。我的应用被拒绝了,因为它必须遵循iOS数据存储指南。我已经在Stack Overflow上阅读了一些答案,我已经阅读了一些博客。

我在appdelegate.m中使用以下方法停止icloud备份。我的数据库大小是79mb。

- (BOOL)addSkipBackupAttributeToItemAtPath:(NSString *)path {
    NSURL *url = [NSURL fileURLWithPath: path];
    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;
}

我也使用过这段代码:

 NSArray *pathsa = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
    NSString *basePath = ([pathsa count] > 0) ? [pathsa objectAtIndex:0] : nil;
    NSArray *documents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:basePath error:nil];
    NSURL *URL;
    NSString *completeFilePath;
    for (NSString *file in documents) {
        completeFilePath = [NSString stringWithFormat:@"%@/%@", basePath, file];
        URL = [NSURL fileURLWithPath:completeFilePath];
        NSLog(@"File %@  is excluded from backup %@", file, [URL resourceValuesForKeys:[NSArray arrayWithObject:NSURLIsExcludedFromBackupKey] error:nil]);
    }

但它仍然在iCloud Storage中显示109 MB。

0 个答案:

没有答案