-->

不过备份到iCloud即使addSkipBackupAttributeToItemAtURL实现?(

2019-06-24 21:47发布

我最近的iOS应用刚刚拒绝了,因为应用程序存储上的文件数据,因此它被iCloud的备份,这是不允许的,因为数据是从服务器下载。

我想,现在重建的代码,并保存在一个文件夹卡列斯应用支持的数据时,而不是击中一个艰难的地方。

但是,即使我使用addSkipBackupAttributeToItemAtURL它仍然显示了作为备份到iCloud。

我只针对5.1,所以它不是一个版本的问题。

我已经添加了受影响的代码在这里如下:

    NSString *newPath = [NSMutableString stringWithFormat:@"%@/Library/Application Support/", NSHomeDirectory()];

    if (![[NSFileManager defaultManager] fileExistsAtPath:newPath]) //Does directory already exist?
    {
        if (![[NSFileManager defaultManager] createDirectoryAtPath:newPath
                                       withIntermediateDirectories:NO
                                                        attributes:nil
                                                             error:&error])
        {
            NSLog(@"Create directory error: %@", error);
        }

    }

    NSString *guidesPath = [newPath stringByAppendingPathComponent:@"/Guides"];
    if (![[NSFileManager defaultManager] fileExistsAtPath:guidesPath])  //Does directory already exist?
    {
        if (![[NSFileManager defaultManager] createDirectoryAtPath:guidesPath
                                       withIntermediateDirectories:NO
                                                        attributes:nil
                                                             error:&error])
        {
            NSLog(@"Create directory error: %@", error);
        }

    }

    NSString *dataPath = [guidesPath stringByAppendingPathComponent:dbName];

    if (![[NSFileManager defaultManager] fileExistsAtPath:dataPath])
    {
        if (![[NSFileManager defaultManager] createDirectoryAtPath:dataPath
                                       withIntermediateDirectories:NO
                                                        attributes:nil
                                                             error:&error])
        {
            NSLog(@"Create directory error: %@", error);
        }

    }

    NSString *newGuidesPath = [dataPath stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSURL *guidesURL = [NSURL URLWithString:newGuidesPath];
    [self addSkipBackupAttributeToItemAtURL:guidesURL];

    NSString* path = [dataPath stringByAppendingPathComponent: 
                      [NSString stringWithString: finalName] ];
    if (![fileManager fileExistsAtPath:path]) {
        [myData writeToFile:path atomically:YES];
        NSString *docFile = [dataPath stringByAppendingPathComponent: @"guideid.txt"];
        [[guideID dataUsingEncoding:NSUTF8StringEncoding] writeToFile:docFile atomically:NO];
        DLog(@"Saved database here:%@", path);
    }else{
        DLog(@"Already exists, no need to copy");
    }

}

 - (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL
{


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

Answer 1:

其实找到一个解决办法,我已经编码这是没有必要的URL。 刚刚将该文件夹

    NSURL *guidesURL = [NSURL fileURLWithPath:guidesPath];
    [guidesURL setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:NULL];

而跳过了排除法,只是标记它的代码,这似乎在里面工作。



Answer 2:

你尝试创建新的设备上从iCloud中设置备份?



文章来源: Still backups to iCloud even when addSkipBackupAttributeToItemAtURL is implemented?