2012-09-26 34 views
5

我正在與PhoneGap(現在的Apache Cordova,2.0版本)的應用程序,並使用PhoneGap文件AP​​I寫入文件。它能夠測試PhoneGap File API與紋波模擬器

文件API我用可以在被引用: http://docs.phonegap.com/en/2.0.0/cordova_file_file.md.html#File

我用波紋模擬器(0.9.9beta)從這裏:https://developer.blackberry.com/html5/download來測試我的鍍鉻的應用。

但我發現Ripple無法正確處理PhoneGap File API。

例如:

我想在持久目錄下創建一個文件(根/ foo.json)

function onSuccess(fileSystem) { 
    fileSystem.root.getDirectory("dir", {create: true}, function(dirEntry){ 
     dirEntry.getFile("foo.json", {create: true}, function(fileEntry){  
      fileEntry.createWriter(function(writer){ 
       writer.write(JSON.stringify(fooData)); 
      }, onfail); 
     }, onfail); 
    }, onfail); 
} 
function onfail(error) 
{ 
    console.log(error.code); 
} 

// request the persistent file system 
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onSuccess, onfail); 

它工作正常,在iOS模擬器,它確實創造了在正確的文件但是在使用chrome運行的Ripple Emulator中,我剛接到一個onfail回調,並得到了錯誤代碼10(FileError.QUOTA_EXCEEDED_ERR)。

我還發現有人用類似的問題在這裏:Is it able to test phonegap application outside emulator?

但始終無人接聽。

漣漪仿真程序目前無法爲PhoneGap API正常工作嗎?或者我錯過了一些設置?

+0

我想我可能會得到答案,Ripple目前支持PhoneGap API的子集,並且正在進行工作以完成它:(http://rippledocs.tinyhippos.com/index.html#platforms/phoneGap – windam

回答

3

發現問題。我需要在使用PERSISTENT文件系統對象之前授予配額。 https://developers.google.com/chrome/whitepapers/storage#persistent

// Request Quota (only for File System API) 

window.webkitStorageInfo.requestQuota(PERSISTENT, 1024*1024, function(grantedBytes) { 
window.webkitRequestFileSystem(PERSISTENT, grantedBytes, onInitFs, errorHandler); 
}, function(e) { 
console.log('Error', e); 
}); 

看來紋波UI並沒有爲我做到這一點(我檢查在LIB /紋波/ fs.js的源代碼)。這就是爲什麼我總是得到一個FileError.QUOTA_EXCEEDED_ERR。

+0

有趣Chrome是否會自動爲你做這件事?如果是這樣,我很好奇Ripple不會繼承它所運行的瀏覽器的行爲。 –