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

发布于 2024-12-24 17:22:13 字数 180 浏览 1 评论 0原文

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

Hi i am about to submit my application to App store.I read that there are few changes in apples data storage guidelines as iCloud storage is introduced.i was saving all user's data in applications documents directory since the contents of the documents directory are automatically backed up to the iCould,if enabled,i am thinking to move them to applications Library directory.Is it approved to save contents in to library considering data storage guidelines of apple?If not where to save the data? Please help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

ま柒月 2024-12-31 17:22:14

您有两个主要选择:

You have two main options:

  • Put your files in the Cache directory then they won't be backed up and Apple won't reject your app. However, when iOS 5 gets low on space it may delete all the files in there
  • Put files in Documents but flag them so that they are not backed up. There's a technote (QA1719) on how to do this. This only works in iOS 5.0.1 and later
明媚如初 2024-12-31 17:22:14

您可以将数据放入文档文件夹中,但在保留文档文件夹之前,请在文档文件夹中创建一个文件夹(假设为 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;
}

You can put data in Documents folder but before keep in documents folder create a folder within Documents folder suppose namely temp. Then write the following code to not backup in iCloud.

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

Also implement the method addSkipBackupAttributeToItemAtURL
do not forget to include

#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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文