問題描述
到目前為止,我能想到的最好的方法是彈出一個窗口,要求用戶禁用 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?)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!