【问题标题】:iPhone:Where to save the users data when icloud back up is not requirediPhone:不需要icloud备份时将用户数据保存在哪里
【发布时间】:2012-01-03 12:34:19
【问题描述】:

您好,我即将向 App Store 提交我的应用程序。我了解到,随着 iCloud 存储的引入,苹果数据存储指南几乎没有变化。由于文档目录的内容,我将所有用户的数据保存在应用程序文档目录中自动备份到 iCould,如果启用,我正在考虑将它们移动到应用程序库目录。考虑到苹果的数据存储准则,是否批准将内容保存到库中?如果不保存数据在哪里?请帮忙。

【问题讨论】:

    标签: iphone ipad appstore-approval data-storage


    【解决方案1】:

    您有两个主要选择:

    • 将您的文件放在缓存目录中,然后它们不会被备份,Apple 也不会拒绝您的应用程序。但是,当 iOS 5 空间不足时,它可能会删除其中的所有文件
    • 将文件放入 Documents 中,但对其进行标记以便不备份。有一个关于如何执行此操作的技术说明 (QA1719)。这仅适用于 iOS 5.0.1 及更高版本

    【讨论】:

      【解决方案2】:

      您可以将数据放在 Documents 文件夹中,但在保存在 Documents 文件夹中之前,请在 Documents 文件夹中创建一个文件夹,假设为 temp。然后编写以下代码不备份到 iCloud。

      [[NSFileManager defaultManager] createDirectoryAtPath:temp 
                                withIntermediateDirectories:NO
                                                 attributes:nil
                                                      error:nil];
      NSURL *dbURLPath = [NSURL URLWithString:temp];
      [self addSkipBackupAttributeToItemAtURL:dbURLPath]; 
      

      同样实现方法addSkipBackupAttributeToItemAtURL 不要忘记包括

      #include <sys/xattr.h>
      
      - (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL {
          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;
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-07-30
        • 2012-09-04
        • 2013-11-16
        • 2012-03-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-08-24
        相关资源
        最近更新 更多