Is it able to test PhoneGap File API with Ripple emulator

牧云@^-^@ 提交于 2019-12-06 02:25:49

问题


I am working on an application with PhoneGap (now Apache Cordova, with the version of 2.0), and using the PhoneGap File API to write file.

The File API I use could be referenced at: http://docs.phonegap.com/en/2.0.0/cordova_file_file.md.html#File

I use Ripple Emulator (0.9.9beta) from here: https://developer.blackberry.com/html5/download to test my application in chrome.

But I find Ripple could not handle the PhoneGap File API correctly.

For example:

I want to create a file (root/foo.json) at the PERSISTENT directory

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);

It works fine on iOS simulator, which did create the right file at the right place, but in the Ripple Emulator running in chrome, I just got a onfail callback, and got error code 10 (FileError.QUOTA_EXCEEDED_ERR).

I also found someone with the similar question here: Is it able to test phonegap application outside emulator?

But still no answer.

Does Ripple emulator currently not work correctly for PhoneGap API? Or did I missed some setting?


回答1:


Problem found. I need to grant quota before using the PERSISTENT filesystem object. 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); 
});

It seems Ripple-UI didn't do this for me (I checked the source code at lib/ripple/fs.js) . That's why I always get a FileError.QUOTA_EXCEEDED_ERR.



来源:https://stackoverflow.com/questions/12598292/is-it-able-to-test-phonegap-file-api-with-ripple-emulator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!