不要备份到iCloud但仍然拒绝

Nik*_*rov 16 storage objective-c app-store ios icloud

在我的应用程序中,我必须存储核心数据数据库和音频文件,所以我解码将它们放在Documents目录中.为了防止它们备份,当我第一次启动应用程序时,我把这样的Do not BackUp标志

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
 [self addSkipBackupAttributeToItemAtURL:[self applicationDocumentsDirectory]];
}
    - (NSURL *)applicationDocumentsDirectory
{
    return [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
}
- (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL
{
  if (&NSURLIsExcludedFromBackupKey == nil) { // iOS <= 5.0.1
    const char* filePath = [[URL path] fileSystemRepresentation];

    const char* attrName = "com.apple.MobileBackup";
    u_int8_t attrValue = 1;

    int result = setxattr(filePath, attrName, &attrValue, sizeof(attrValue), 0, 0);
    return result == 0;
  } else { // iOS >= 5.1
    return [URL setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:nil];
  }
}
Run Code Online (Sandbox Code Playgroud)

但似乎它不起作用 - 我仍然被拒绝:

我们发现您的应用不符合iOS数据存储指南,这是根据App Store审核指南所要求的.

特别是,我们发现在启动和/或内容下载时,您的应用程序存储了3.6 MB.要检查应用存储的数据量:

  • 安装并启动您的应用
  • 转至设置> iCloud>存储和备份>管理存储
  • 如有必要,请点按"显示所有应用"
  • 检查您应用的存储空间

而另一个问题是我无法检查 - 我没有看到我的应用程序

设置> iCloud>存储和备份>管理存储

也许问题只有5.0,我有点想不到这里?

Oma*_*ith 9

问题是iOS 5.0,在这个iOS你不应该把备用标志在ios 5.0.1中引入了不备份标志我们确实遇到了与我们的应用程序类似的问题,它被拒绝了几次所以我们不得不这样做解决不同iOS的问题我们需要支持iOS <5.0,iOS 5.0和iOS> 5.0

所以在联系apple之后,我们没有找到任何解决方案,除了在不同的iOS上有不同的路径

我们有这样的功能:

+ (NSString*) savePath
{
    NSString *os5 = @"5.0";

    NSString *currSysVer = [[UIDevice currentDevice] systemVersion];
    NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];

    if ([currSysVer compare:os5 options:NSNumericSearch] == NSOrderedAscending) //lower than 4
    {
        return path;
    }
    else if ([currSysVer compare:os5 options:NSNumericSearch] == NSOrderedDescending) //5.0.1 and above
    {        
        return path;
    }
    else // IOS 5
    {
        path = [NSHomeDirectory() stringByAppendingPathComponent:@"Library/Caches"];
        return path;
    }

    return nil;
}
Run Code Online (Sandbox Code Playgroud)

我们使用并仍然使用此功能.

请阅读更多

iOS 5.0

无法从iOS 5.0上的备份中排除数据.如果您的应用必须支持iOS 5.0,那么您需要将应用数据存储在缓存中以避免备份数据.iOS将在必要时从Caches目录中删除您的文件,因此如果删除了数据文件,您的应用程序将需要正常降级.

http://developer.apple.com/library/ios/#qa/qa1719/_index.html