iOS沙盒Documents目录下的文件默认会被iCloud 和 iTunes同步。可以通过代码指定某个文件或者文件夹不被同步。
iOS5.1及以后可以使用如下代码
- (BOOL)addjianshuSkipBackupAttributeToItemAtPath:(NSString *) filePathString
{
NSURL* URL= [NSURL fileURLWithPath: filePathString];
assert([[NSFileManager defaultManager] fileExistsAtPath: [URL path]]);
NSError *error = nil;
BOOL success = [URL setResourceValue: [NSNumber numberWithBool: YES]
forKeyjianshuRLIsExcludedFromBackupKey error: &error];
if(!success){
NSLog(@"Error excluding %@ from backup %@", [URL lastPathComponent], error);
}
return success;
}
iOS5.0.1
#import <sys/xattr.h>
- (BOOL)addSkipBackupAttributeToItemAtPath:(NSString *) filePathString
{
assert([[NSFileManager defaultManager] fileExistsAtPath: filePathString]);
const char* filePath = [filePathString 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;
}
网友评论