APP被苹果拒绝,说是document等文件夹不能备份到iCloud

iOS 码拜 8年前 (2016-03-25) 1703次浏览
本人加上上了阻止文件备份到iCloud里的代码,结果还是被苹果打回来了APP被苹果拒绝,说是document等文件夹不能备份到iCloud
跪求高手指点啊。
本人的代码如下:
在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目录;

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明APP被苹果拒绝,说是document等文件夹不能备份到iCloud
喜欢 (0)
[1034331897@qq.com]
分享 (0)