16

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

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

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

我们发现您的应用未遵循 App Store 审核指南所要求的 iOS 数据存储指南。

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

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

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

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

也许问题只出在我在这里没有考虑的 5.0 上?

4

1 回答 1

9

问题在于 iOS 5.0,在这个 iOS 中你不应该放置 dont backup 标志 dont back up 标志是在 ios 5.0.1 中引入的 我们的应用确实遇到了类似的问题,它已经被拒绝了好几次所以我们不得不做处理不同 iOS 的解决方法 我们需要支持 iOS < 5.0、iOS 5.0 和 iOS > 5.0

所以在联系苹果之后,除了在不同的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;
}

我们使用并仍在使用此功能。

请阅读更多

iOS 5.0

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

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

于 2012-06-05T06:51:15.650 回答