Iphone 使用NSFileProtectionComplete加密核心数据库是否也能在与iTunes同步期间保护数据?

Iphone 使用NSFileProtectionComplete加密核心数据库是否也能在与iTunes同步期间保护数据?,iphone,ipad,core-data,sqlite,Iphone,Ipad,Core Data,Sqlite,使用NSFileProtectionComplete加密核心数据是否可以防止它将数据库同步到iTunes?否。如果用户的设备上有密码,NSFileProtectionComplete只会加密核心数据文件。它不会更改设备的备份行为 控制备份行为因iOS版本而异 在5.1及更高版本中,您可以使用 assert([[NSFileManager defaultManager] fileExistsAtPath: [URL path]]); NSError *error = nil; BOOL succ

使用NSFileProtectionComplete加密核心数据是否可以防止它将数据库同步到iTunes?

否。如果用户的设备上有密码,NSFileProtectionComplete只会加密核心数据文件。它不会更改设备的备份行为

控制备份行为因iOS版本而异

在5.1及更高版本中,您可以使用

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);
}