2012-12-14 69 views
0

我在閱讀關於此問題的許多問題。我爲我的應用使用了Phonegap。 我的應用程序下載約3mb的圖像。 Apple拒絕我的應用程序,並建議將「不備份屬性」應用於所有文件。 How do I prevent files from being backed up to iCloud and iTunes?2.23應用程序必須遵循iOS數據存儲指南,否則它們將被拒絕

我使用此代碼爲我的5.1應用程序:

- (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL 
{ 
     assert([[NSFileManager defaultManager] fileExistsAtPath: [URL path]]); 

     NSError *error = nil; 
     BOOL success = [URL setResourceValue: [NSNumber numberWithBool: YES] 
           forKey: NSURLIsExcludedFromBackupKey error: &error]; 
     if(!success){ 
     NSLog(@"Error excluding %@ from backup %@", [URL lastPathComponent], error); 
     } 
     return success; 
} 

我把它放在我的AppDelegate.m。這是對的嗎?

+1

我想補充說,所有的文件都在「/ var/mobile/Applications/CEEECEA6-4684-4599-B0BF-407BE2CBD3CE/Library/Caches /」 – Corallino

回答

1

你現在在哪裏存儲文件?

window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onSuccess, null); 

一個解決方案是使用下面爲您FileSytem請求的代碼,這將requets您的應用程序的臨時目錄:

window.requestFileSystem(LocalFileSystem.TEMPORARY, 0, onSuccess, onError); 

LocalFileSystem.TEMPORARY對我你可以使用標準的PhoneGap例如猜iOS版將指向

/var/mobile/Applications/CEEECEA6-4684-4599-B0BF-407BE2CBD3CE/tmp 

親切的問候,

麥克

+0

我使用PERSISTENT,因爲我需要讓我的數據離線。在tmp文件夾中,我丟失了所有數據。我讀過,如果我把數據放入Library/Caches中,它會被iCloud忽略。但蘋果拒絕我的應用程序。 – Corallino

+0

只有當您正在運行的設備的數據運行不足時,纔會刪除/ tmp文件夾中的數據。相同的緩存... – NDakotaBE

+0

好吧,我正在修改/ var/mobile/Applications/CEEECEA6-4684-4599-B0BF-407BE2CBD3CE/tmp中的路徑。但是,仍然當我檢查 - 去設置> iCloud的>存儲和備份>管理存儲和 檢查我的應用程序的存儲空間,仍然是2,3 MB。 – Corallino

0

這是我的代碼

var DATADIR; 
    var knownfiles = []; 

    function init() { 
     document.addEventListener("deviceready", onDeviceReady, true); 
    } 

    function onDeviceReady() { 
      window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFSSuccess, null);  
    } 

    //Loaded my file system, now let's get a directory entry for where I'll store my crap  
    function onFSSuccess(fileSystem) { 
     fileSystem.root.getDirectory("it.mns.dcsofficebp",{create:true},gotDir,onError); 
    } 

    //The directory entry callback 
    function gotDir(d){ 
     DATADIR = d; 
     var reader = DATADIR.createReader(); 
     localStorage.setItem("datadir",JSON.stringify(DATADIR)); 
     reader.readEntries(function(d){ 
      appReady(); 
     },onError); 
    } 

    //Result of reading my directory 
    function gotFiles(entries) { 
     for (var i=0; i<entries.length; i++) { 
       knownfiles.push(entries[i].name); 
       renderPicture(entries[i].fullPath); 
      } 
     } 

,我需要把

parent.setMetadata(onSetMetadataSuccess, onSetMetadataFail, { "com.apple.MobileBackup": 1}); 
0

這應該是在我身邊工作的正確代碼:

var DATADIR; 
var knownfiles = []; 

function init() { 
      window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFSSuccess, null); 
} 

function onFSSuccess(fileSystem) { 
    console.log("here I am"); 
    fileSystem.root.getDirectory("it.mns.dcsofficebp",{create:true},gotDir,false); 
} 
function gotDir(d){ 
    DATADIR = d; 
    DATADIR.setMetadata(onSetMetadataSuccess, onSetMetadataFail, { "com.apple.MobileBackup": 1}); 
} 

function onSetMetadataSuccess() { 
    console.log("success setting metadata - DONE DONE DONE!") 
} 
function onSetMetadataFail() { 
    console.log("error setting metadata") 
} 

這是我的結果:2012-12-14 12:46:20.064 testproj [1779:c07] [LOG]成功設置元數據 - 完成完成!

+0

我正在嘗試你的例子。但停止使用此消息:2012-12-14 12:32:39.676 dcsofficebp [3027:907] [INFO]成功回調錯誤:File2 = TypeError:'undefined'不是函數 – Corallino

+0

嘗試設置'DATADIR.setMetadata('至'd.setMetadata' – NDakotaBE

+0

此外,'{「com.apple.MobileBackup」:0}'需要爲'{「com.apple.MobileBackup」:1}'。 – NDakotaBE

相關問題