亲测自己查阅资料解决,其实也不怎么难= =,好了,直接说解决思路。很简单,直接让iCloud 忽略 document的目录 不备份就可以了。没错,思路就是这么简单。
下面是苹果官方的方法 https://developer.apple.com/library/prerelease/content/qa/qa1719/_index.html
下面是我自己的代码:
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
//解决2.1.1被拒问题,忽略document文件放置iCloud备份
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
if (paths.count > 0) {
NSLog(@"NSDocumentDirectory paths = %@",paths[0]);
[self addSkipBackupAttributeToItemAtPath:paths[0]];
}
return YES;
}
/**
* 跳过iCloud 存储
*
* @param filePathString app的url
*
* @return
*/
- (BOOL)addSkipBackupAttributeToItemAtPath:(NSString *) filePathString
{
NSLog(@"%s",__func__);
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;
}
第二段代码是苹果官方的, 用 NSURLIsExcludedFromBackupKey or kCFURLIsExcludedFromBackupKey 这两个文件系统属性把文件从备份文件中排除。
我忽略的是document 的路径,相应的总结一下其他 文件的路径 = =,可忽略
//1,获取家目录路径的函数:
NSString *homeDir = NSHomeDirectory();
//2,获取Documents目录路径的方法:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docDir = [paths objectAtIndex:0];
//3,获取Caches目录路径的方法:
NSArray *paths2 = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *cachesDir = [paths2 objectAtIndex:0];
//4,获取tmp目录路径的方法:
NSString *tmpDir = NSTemporaryDirectory();
//5,获取应用程序程序包中资源文件路径的方法:
//例如获取程序包中一个图片资源(apple.png)路径的方法:
NSString *imagePath = [[NSBundle mainBundle] pathForResource:@"apple" ofType:@"png"];
UIImage *appleImage = [[UIImage alloc] initWithContentsOfFile:imagePath];
//代码中的mainBundle类方法用于返回一个代表应用程序包的对象。
下面是参考的博客 :
http://blog.csdn.net/wm9028/article/details/50293139
http://blog.csdn.net/shanglanxin/article/details/50395583
http://www.cnblogs.com/lzlsky/p/3333139.html