iPhone:不需要icloud备份时保存用户数据的位置

时间:2012-01-03 12:34:19

标签: iphone ipad appstore-approval data-storage

您好我将我的应用程序提交到App store。我读到,随着iCloud存储的推出,苹果数据存储指南几乎没有变化。我将所有用户的数据保存在应用程序文档目录中,因为文件目录的内容自动备份到iCould,如果启用,我打算将它们移动到应用程序库目录。它是否批准将内容保存到库中,考虑到苹果的数据存储指南?如果没有保存数据的位置?请帮忙。

2 个答案:

答案 0 :(得分:0)

您有两个主要选择:

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

答案 1 :(得分:0)

您可以将数据放入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;
}