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

Cri*_*682 5 iphone appstore-approval ios icloud

我的应用程序被拒绝,因为似乎7 MB存储在文档文件夹中,它们会自动发送到icloud.所以我已经通过这种方法循环将写入文档文件夹的所有文件:

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

   const char* filePath = [[URL path] fileSystemRepresentation];
   const char* attrName = "com.apple.MobileBackup";
   if (&NSURLIsExcludedFromBackupKey == nil) {
   // iOS 5.0.1 and lower
   u_int8_t attrValue = 1;
   int result = setxattr(filePath, attrName, &attrValue, sizeof(attrValue), 0, 0);
   return result == 0;
 }
  else {
   // First try and remove the extended attribute if it is present
   int result = getxattr(filePath, attrName, NULL, sizeof(u_int8_t), 0, 0);
   if (result != -1) {
       // The attribute exists, we need to remove it
       int removeResult = removexattr(filePath, attrName, 0);
       if (removeResult == 0) {
           NSLog(@"Removed extended attribute on file %@", URL);
       }
   }

   // Set the new key
   NSError *error = nil;
   [URL setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:&error];
   return error == nil;
  }
Run Code Online (Sandbox Code Playgroud)

我的应用程序的1.1版本在此代码实现后获得批准.上周我试图发送相同应用程序的1.2版本(文件管理中没有任何变化,存储在文档文件夹中的所有文件都通过addSkipBackupAttributeToItemAtURL方法循环).出于同样的原因,我的应用再次遭到拒绝.我无法将我的文件移动到临时文件夹或缓存文件夹,因为我的应用程序无法完全恢复文件(其中一个文件是数据库,恢复数据库意味着任何用户插入的数据都松散),所以这一个不能解决.无论如何,我在代码中发现了一个问题,这就是我调用方法的方法:

[self addSkipBackupAttributeToItemAtURL:[NSURL fileURLWithPath:fullPath]];

使用[NSURL fileURLWithPath:fullPath]设备与ios 5.1返回错误,似乎无法创建属性.如果我用[NSURL URLWithString:defaultStorePath]更改nsurl的初始化,带5.1的设备似乎正确添加了该属性.

对于ios 5.0.1,所有都被反转,[NSURL URLWithString:defaultStorePath]在[NSURL fileURLWithPath:fullPath]工作时返回错误.

也许我可以检查ios版本并设置适当的nsurl初始化,但它仍然是一个问题.拒绝解释我读到:

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

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

如果我试图检查这个值,我看到7 mb也正确的nsurl初始化(当所有属性设置正确时).什么是正确的行为?谁有这个问题?在苹果建议的应用程序存储检查之前,我是否必须做一些特定的事情才能使其显着?

Jon*_*Jon 0

我遇到了与您相同的问题,直到我从设备中删除了我的应用程序并重新安装。我还必须通过转到“设置”->“存储和备份”->“管理存储”来从 iCloud 备份中删除现有的缓存数据

这似乎成功了。另外,我添加跳过属性的代码有点不同: 从这篇文章中提取的代码

- (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL
{
   assert([[NSFileManager defaultManager] fileExistsAtPath: [URL path]]);

   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
      NSError *error = nil;
      [URL setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:&error];
      return error == nil;
   }


}
Run Code Online (Sandbox Code Playgroud)