它是否能够测试PhoneGap文件AP​​I与Ripple仿真器 [英] Is it able to test PhoneGap File API with Ripple emulator

查看:144
本文介绍了它是否能够测试PhoneGap文件AP​​I与Ripple仿真器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

我使用的API可以参考:
http://docs.phonegap。 com / en / 2.0.0 / cordova_file_file.md.html#File

The File API I use could be referenced at: 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中测试我的应用程序。

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

但我发现Ripple无法正确处理PhoneGap文件AP​​I。

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

例如:

我想在PERSISTENT目录中创建一个文件(root / foo.json)

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

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

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

我也发现有类似的问题在这里: a href =http://stackoverflow.com/questions/12541107/is-it-able-to-test-phonegap-application-outside-emulator>是否能够在模拟器外测试phonegap应用程序?

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

但仍然没有回答。

Ripple模拟器目前无法正常使用PhoneGap API吗?还是我错过了一些设置?

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

推荐答案

发现问题。我需要在使用PERSISTENT文件系统对象之前授予配额。
https://developers.google.com/chrome/whitepapers/storage#persistent

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

看起来Ripple-UI没有为我做这个ripple / fs.js)。这就是为什么我总是得到一个FileError.QUOTA_EXCEEDED_ERR。

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.

这篇关于它是否能够测试PhoneGap文件AP​​I与Ripple仿真器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆