本人加上上了阻止文件备份到iCloud里的代码,结果还是被苹果打回来了
跪求高手指点啊。
本人的代码如下:
在AppDelegate.m中:
跪求高手指点啊。
本人的代码如下:
在AppDelegate.m中:
//设置禁止Document和Library目录下的文件同步到iCloud -(void)addNotBackUpiCloud{ NSArray *docPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSArray *libPaths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES); NSString *docPath = [docPaths objectAtIndex:0]; NSString *libPath = [libPaths objectAtIndex:0]; [self fileList:docPath]; [self fileList:libPath]; } - (void)fileList:(NSString*)directory{ NSError *error = nil; NSFileManager * fileManager = [NSFileManager defaultManager]; NSArray *fileList = [fileManager contentsOfDirectoryAtPath:directory error:&error]; for (NSString* each in fileList) { NSMutableString* path = [[NSMutableString alloc]initWithString:directory]; [path appendFormat:@"/%@",each]; NSURL *filePath = [NSURL fileURLWithPath:path]; [self addSkipBackupAttributeToItemAtURL:filePath]; [self fileList:path]; } } - (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL { //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; }
然后
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [self addNotBackUpiCloud];
解决方案
40
两个方案:
1. 在document目录下面创建子目录,专门用于放置你的数据;并且把该目录设置为不备份;
2. 直接把你的数据,放置在Library目录下面,不要放到 document目录;
1. 在document目录下面创建子目录,专门用于放置你的数据;并且把该目录设置为不备份;
2. 直接把你的数据,放置在Library目录下面,不要放到 document目录;