2012-04-10 111 views
1

根據蘋果網站上的開發者文檔:https://developer.apple.com/library/ios/#qa/qa1719/_index.html的PhoneGap /科爾多瓦1.5 iOS的「不備份」文件屬性

iOS中起5.0.1新的「不備份」文件屬性已引入允許開發人員明確指定應備份哪些文件。 (com.apple.MobileBackup)

如果這是在PhoneGap的/科爾多瓦的支持,我不知道,因爲我希望能夠存儲一些離線數據(可以下載或以其他方式重新創建數據,但該用戶希望在脫機狀態下可以可靠地使用),而這些數據在iCloud上未備份。

PhoneGap網站上明確記錄了持久性(LocalFileSystem.PERSISTENT - http://docs.phonegap.com/en/1.5.0/phonegap_file_file.md.html#LocalFileSystem),但似乎無法確保保存的文件未備份到iCloud。

回答

3

我仍然堅持要的PhoneGap /科爾多瓦內,但作爲一個臨時變通的解決方案......

在我的AppDelegate初始化:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 

// Get documents directory 
NSString *documentsDirectory = [paths objectAtIndex:0]; 
NSString *formularyPath = [documentsDirectory stringByAppendingPathComponent:@"OfflineData"]; 

if (![[NSFileManager defaultManager] fileExistsAtPath:formularyPath]) 
    [[NSFileManager defaultManager] createDirectoryAtPath:formularyPath withIntermediateDirectories:NO attributes:nil error:nil]; 

// Prevent iCloud backup 
u_int8_t b = 1; 
setxattr([formularyPath fileSystemRepresentation], "com.apple.MobileBackup", &b, 1, 0, 0); 

不要忘記#進口「 sys/xattr.h「

這將在文檔下創建一個新文件夾並設置no backup屬性。

然後,您可以使用持久本地文件存儲選項將文件保存在PhoneGap中,並且不會備份保存在新子目錄中的文件。

+0

感謝您的回答@LeeCrossley !!我參與了一個PhoneGap項目,該項目下載的數據應該保留並且不被備份,但是,由於我們使用的版本是1.7,我們不能使用'setMetadata'函數並升級到1。8現在會相當混亂。只是一個問題,你有沒有發佈任何與此代碼的應用程序商店?我沒有看到它被拒絕的原因,但是,由於我既沒有經驗,也沒有在應用商店發佈的經驗,所以我想確定它是否可以 – davids 2012-08-21 09:46:39

+0

是的,這個應用程序:itunes。 apple.com/gb/app/nice-bnf/id523093958使用上面的代碼,目前運行1.7。 – 2012-09-14 10:33:38

4

這是一個功能強大的JS代碼示例,它利用了Cordova框架,我相信它可以解決Apple正在尋找的問題。

document.addEventListener("deviceready",onDeviceReady,false); 

function onSetMetadataSuccess() { 
    console.log("success setting metadata - DONE DONE DONE!") 
} 
function onSetMetadataFail() { 
    console.log("error setting metadata") 
} 
function onGetDirectorySuccess(parent) { 
    console.log("success getting dir"); 
    parent.setMetadata(onSetMetadataSuccess, onSetMetadataFail, { "com.apple.MobileBackup": 1}); 
} 
function onGetDirecotryFail() { 
    console.log("error getting dir") 
} 

function onFileSystemSuccess(fileSystem) { 
    console.log("onFileSystemSuccess()") 

    var dirEntry = fileSystem.root; 
    dirEntry.getDirectory('Backups', {create: true, exclusive: false}, 
      onGetDirectorySuccess, onGetDirecotryFail); 

} 

function onFileSystemFail(evt) { 
    console.log("!!!!! onFileSystem fail...") 
    console.log(evt.target.error.code); 
} 

/* When this function is called, PhoneGap has been initialized and is ready to roll */ 
function onDeviceReady() 
{ 

    // this and subsequent callbacks tells iOS not to store our data in iCloud. 
    // without it they rejected our app because of the way PG 1.8 does local->tem storage 
    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFileSystemSuccess, onFileSystemFail); 

} 
4

由於PhoneGap的1.9,你可以在你的config.xml中設置:

<preference name="BackupWebStorage" value="none" /> 

BackupWebStorage(字符串,默認爲雲):有效值爲none,雲和本地。設置爲允許將網絡存儲數據備份到iCloud,並設置爲本地以允許本地備份(iTunes同步)。設置爲無,不允許任何Web存儲備份。

要檢查它的工作原理,蘋果公司建議使用此方法來檢查你有多少數據iCloud的主持下提出:

  • 安裝並運行你的應用程序
  • 進入設置> iCloud中>存儲&備份>管理存儲
  • 如有必要,請點擊「顯示所有的應用程序」
  • 檢查您的應用程序的存儲

請注意,這不能在模擬器中完成。你需要一個真正的設備。

+0

這是近兩年前涉及1.5版本的一個老問題,在該功能實施之前。 – 2014-01-29 11:26:46

+2

是的,你是對的,但問題仍然存在,我想幫助其他用戶。 – 2014-01-29 11:29:09

+1

我試過了,但仍然不能工作:( – 2014-03-21 04:18:02

相關問題