是否能够使用Ripple仿真器测试PhoneGap File API

win*_*dam 5 file ios ripple cordova

我正在使用PhoneGap(现在是Apache Cordova,版本为2.0)的应用程序,并使用PhoneGap File API来编写文件.

我使用的File API可以在以下网址引用:http: //docs.phonegap.com/en/2.0.0/cordova_file_file.md.html#File

我从这里使用Ripple Emulator(0.9.9beta):https://developer.blackberry.com/html5/download来测试我在chrome中的应用程序.

但我发现Ripple无法正确处理PhoneGap File API.

例如:

我想在PERSISTENT目录中创建一个文件(root/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);
Run Code Online (Sandbox Code Playgroud)

它在iOS模拟器上工作正常,它确实在正确的位置创建了正确的文件,但是在chrome中运行的Ripple Emulator中,我只得到一个onfail回调,并得到错误代码10(FileError.QUOTA_EXCEEDED_ERR).

我也在这里找到了一个类似问题的人:它是否能够在模拟器外测试phonegap应用程序?

但仍然没有答案.

Ripple仿真器目前无法正常用于PhoneGap API吗?或者我错过了一些设置?

win*_*dam 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); 
});
Run Code Online (Sandbox Code Playgroud)

看来 Ripple-UI 并没有为我做到这一点(我在 lib/ripple/fs.js 检查了源代码)。这就是为什么我总是收到 FileError.QUOTA_EXCEEDED_ERR 的原因。