【问题标题】:Unexpected data saved in iCloudiCloud 中保存的意外数据
【发布时间】:2016-01-24 12:10:34
【问题描述】:

由于以下原因,我的一个应用刚刚被拒绝:

2.23 - 应用必须遵循 iOS 数据存储指南,否则将被拒绝

2.23 详情

在启动和内容下载时,您的应用会在用户的 iCloud 上存储 103.72 MB,这不符合 iOS 数据存储指南。

我检查了我的 iPhone,我的应用确实将 200 多 MB 的数据保存到了 iCloud。但是,我很确定我的应用程序中的所有数据都使用 Core Data 保存,并且该应用程序甚至没有在“功能”选项卡中打开 iCloud。那么有没有办法找出这些数据来自哪里?或者您能否提出一些可能导致此问题的原因,以便我进行调查?

编辑

抱歉,我在 Apple 的反馈中遗漏了一行:

有关防止文件备份到 iCloud 和 iTunes 的更多信息,请参阅Technical Q&A 1719: How do I prevent files from being backed up to iCloud and iTunes。

所以我认为审稿人的实际意思是备份了一些不应该备份到iCloud的数据,所以我需要做的就是这样:

- (BOOL)addSkipBackupAttributeToItemAtPath:(NSString *) filePathString {
    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;
}

【问题讨论】:

    标签: ios objective-c core-data app-store-connect icloud


    【解决方案1】:

    这是一个很常见的问题。

    您可以使用application:didFinishLaunchingWithOptions:中的以下代码查看有关iCloud备份的各项权限:

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;
    NSArray *documents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:basePath error:nil];
    NSURL *URL;
    NSString *completeFilePath;
    
    for (NSString *file in documents) {
        completeFilePath = [NSString stringWithFormat:@"%@/%@", basePath, file];
        URL = [NSURL fileURLWithPath:completeFilePath];
        NSLog(@"File %@  is excluded from backup %@", file, [URL resourceValuesForKeys:
                                                              [NSArray arrayWithObject:NSURLIsExcludedFromBackupKey] 
                                                                                 error:nil]);
    }
    

    如果您注意到某些文件正在与 iCloud 同步,您可以将 NSURLIsExcludedFromBackupKey 的资源值设置为 YES 以排除 iCloud 备份这些文件,而不是将这些文件保存在其他位置

    像这样:

    NSURL *URL = [NSURL fileURLWithPath:photoPath];
    [URL setResourceValue:@(YES) forKey:NSURLIsExcludedFromBackupKey error:nil];
    

    【讨论】:

    • 感谢您的回答。我刚刚发现我错过了 Apple 反馈中的一行(我已经编辑了问题)。对此感到抱歉。
    • 我的情况是我在文档中找不到任何文件,备份大小是几KB..
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-08
    • 2015-02-01
    • 2012-02-03
    • 1970-01-01
    • 2014-05-27
    • 1970-01-01
    相关资源
    最近更新 更多