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

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

问题描述

编辑:到目前为止,我能够想出的最好的是一个弹出窗口,要求用户禁用iCloud同步,以及将所有的数据移动到Documents目录,所以它赢得了 t get wiped:在iOS5中,是否可以检测用户是否有应用设置要备份?

So far, the best I've been able to come up with is a pop-up to ask the user to disable iCloud sync, along with moving all the data to the Documents directory so it won't get wiped: In iOS5, is it possible to detect if a user has an app set to back up?

iPhone / iPad的离线地图应用程序。

I develop offline mapping application for iPhone/iPad.

我们曾经在Caches目录中存储所有数据(可能有很多gig)。

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


推荐答案

From: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备份中。),do-not-backup标志兼作do-not-purge标志不是这样的。只要将文件保存在Caches目录中,并标记为不备份就不会阻止其擦除操作。

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天全站免登陆