防止 iCloud 同步数据(使用 .nosync?) [英] Prevent iCloud sync of data (using .nosync?)

查看:29
本文介绍了防止 iCloud 同步数据(使用 .nosync?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

到目前为止,我能想到的最好的方法是弹出一个窗口,要求用户禁用 iCloud 同步,同时将所有数据移动到 Documents 目录,这样它就不会了t 被擦除:在iOS5中,是否可以检测用户是否设置了要备份的应用程序?

我为 iPhone/iPad 开发离线地图应用程序.

I develop offline mapping application for iPhone/iPad.

我们过去将所有数据(可能有很多演出)存储在 Caches 目录中.

We used to store all of the data (many gigs potentially) in the Caches directory.

从 iOS5 开始,当用户的硬盘开始变满时,可以随机删除 Caches 目录中的文件.

As of iOS5, the files in the Caches directory can be randomly deleted when the user's hard drive starts getting full.

如何在不将数据同步到 iCloud、iTunes 且不被随机删除的情况下存储本地数据?我的本地数据是一个大型目录树,其中包含许多小数据文件,位于数千个子目录中.

How can I store local data, without the data being synced to iCloud, iTunes, and without it being randomly deleted? My local data is a large directory tree with many small data files, in thousands of subdirectories.

我将目录树从库缓存目录移动到文档目录中的 data.nosync 目录,因为我们已经阅读过这可能是一个解决方案.但是,nosync 文件夹中的数据仍在备份到 iCloud.

I moved our directory tree from the library cache directory to a data.nosync directory in the documents directory, because we had read this might be a solution. However, the data in the nosync folder is still being backed up to iCloud.

现在我创建目录:

NSString* noSyncDirectory() {
  static NSString *directory = nil;
  if (!directory) {
    directory = [[NSString stringWithFormat:@"%@/%@",
                  documentsDirectory(), @"data.nosync"] retain];
    [Constants createDirectoryIfNeeded:directory];
  }
  return directory;
}

推荐答案

来自:https://developer.apple.com/library/ios/#qa/qa1719/_index.html

您可以使用以下方法设置不备份"扩展属性.每当您创建不应备份的文件或文件夹时,将数据写入文件,然后调用此方法,将 URL 传递给文件.

You can use the following method to set the "do not back up" extended attribute. Whenever you create a file or folder that should not be backed up, write the data to the file and then call this method, passing in a URL to the file.

#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;
}

可以找到更多信息:https://developer.apple.com/icloud/documentation/data-storage/

进一步说明:虽然开发人员文档错误地暗示(这些文件将不会被清除并且不会包含在用户的 iCloud 或 iTunes 备份中.")不备份标志兼作不 -清除标志并非如此.只需将文件留在缓存目录中并标记它们不备份不会阻止它们的擦除.

Further note: While the developer documentation incorrectly implies ("These files will not be purged and will not be included in the user's iCloud or iTunes backup.") that the do-not-backup flag doubles as a do-not-purge flag that is not the case. Simply leaving files in the Caches Directory and flagging them do-not-backup will not prevent their wipe.

这篇关于防止 iCloud 同步数据(使用 .nosync?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆