BlackBerry上的Phonegap / Cordova getDirectory失败

时间:2012-08-03 21:26:29

标签: javascript blackberry cordova blackberry-webworks

我的应用程序在Android和iOS上正常运行,但目前在BlackBerry(OS 6.0+)上失败。该应用程序曾用于处理所有3种风格,但由于转换应用程序以动态下载更新(而不是每次对某些Javascript进行微小更改时重新发布应用程序),该应用程序无法通过getDirectory函数。我正在使用Cordova 1.8.1。

以下是我的JavaScript代码的开始部分,它在设备准备就绪时执行:

function onDeviceReady(){
    // get the filesystem setup and run the pre-loader (follow the callback road)
    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail_FS);
}

function gotFS(fileSystem) {
   fileSystem.root.getDirectory("data", {create: true}, gotDir, fail_GD);   
}

function gotDir(dir) {
    console.log("got dir");
    DATADIR = dir;
    // code for downloading/updating files goes here
    // left out for brevity and lack of relevance at this point
}

function fail_FS(error){
    fail(error,'requestFileSystem');
}

function fail_GD(error){
    fail(error,'getDirectory');
}

function fail(error,call){
    console.log("ERROR: "+call);
    console.log(JSON.stringify(error));
}

我从getDirectory调用(GotFS函数)得到错误代码1。我添加了额外的评论来测试。这就是我所知道的:

fileSystem ='persistent' fileSystem.root.name =“” fileSystem.root.fullPath ='file:/// store'

我已经检查了Cordova herehere上的文档,这是我在config.xml中的内容

<feature id="blackberry.system" required="true" version="1.0.0.0" />
<feature id="org.apache.cordova" required="true" version="1.0.0" />
<feature id="blackberry.find" required="true" version="1.0.0.0" />
<feature id="blackberry.identity" required="true" version="1.0.0.0" />
<feature id="blackberry.pim.Address" required="true" version="1.0.0.0" />
<feature id="blackberry.pim.Contact" required="true" version="1.0.0.0" />
<feature id="blackberry.io.file" required="true" version="1.0.0.0" />
<feature id="blackberry.utils" required="true" version="1.0.0.0" />
<feature id="blackberry.io.dir" required="true" version="1.0.0.0" />
<feature id="blackberry.app" required="true" version="1.0.0.0" />
<feature id="blackberry.app.event" required="true" version="1.0.0.0" />
<feature id="blackberry.system.event" required="true" version="1.0.0.0"/>
<feature id="blackberry.widgetcache" required="true" version="1.0.0.0"/>
<feature id="blackberry.media.camera" />
<feature id="blackberry.invoke" />
<feature id="blackberry.invoke.BrowserArguments" />
<feature id="blackberry.identity" />
<feature id="blackberry.ui.dialog" />
<feature id="blackberry.system" />

<access subdomains="true" uri="file:///store" />
<access subdomains="true" uri="file:///store/data" />
<access subdomains="true" uri="file:///SDCard" />
<access subdomains="true" uri="*" />
<rim:permissions>
    <rim:permit>use_camera</rim:permit>
    <rim:permit>read_device_identifying_information</rim:permit>
    <rim:permit>access_shared</rim:permit>
    <rim:permit>read_geolocation</rim:permit>
</rim:permissions>

其他信息......以下是我的plugins.xml中的内容:

<plugins>
  <plugin name="App"            value="org.apache.cordova.app.App"/>
  <plugin name="Device"         value="org.apache.cordova.device.Device"/>
  <plugin name="Camera"         value="org.apache.cordova.camera.Camera"/>
  <plugin name="NetworkStatus"  value="org.apache.cordova.network.Network"/>
  <plugin name="Notification"   value="org.apache.cordova.notification.Notification"/>
  <plugin name="Accelerometer"  value="org.apache.cordova.accelerometer.Accelerometer"/>
  <plugin name="Geolocation"    value="org.apache.cordova.geolocation.Geolocation"/>
  <plugin name="File"           value="org.apache.cordova.file.FileManager"/>
  <plugin name="FileTransfer"   value="org.apache.cordova.http.FileTransfer"/>
  <plugin name="Contacts"       value="org.apache.cordova.pim.Contact"/>
  <plugin name="Capture"        value="org.apache.cordova.capture.MediaCapture"/>
  <plugin name="Battery"        value="org.apache.cordova.battery.Battery"/>
  <plugin name="Media"          value="org.apache.cordova.media.Media"/>
  <plugin name="ChildBrowser"   value="org.apache.cordova.plugins.childbrowser.ChildBrowser"/>
</plugins>

我怀疑这只是一个简单的事情(就像我在xml中访问权限做错了),但在尝试了各种不同的东西并在互联网上搜索之后,我感到难过...... / p>

任何帮助都将不胜感激。

3 个答案:

答案 0 :(得分:2)

您的代码对我来说是正确的。

如果您将BlackBerry连接到USB并在&#34; USB驱动器&#34;提示时输入了设备密码。屏幕,您将启用大众媒体/存储模式&#39;。这会将文件系统锁定到USB并阻止您的应用访问它。我希望你在尝试调用fileSystem.root.getDirectory时会看到错误。

答案 1 :(得分:2)

我也很喜欢这个。我确信发生此错误有很多原因。

然而,对我来说,当连接USB线时,Blackberry会取消对本地存储和SD卡的访问。 开发时不太有用,一些有意义的错误代码会帮助BB!

希望这有助于其他人。

答案 2 :(得分:1)

对于blackberry10,Cordova / WebWorks会尝试这样做:

window.webkitRequestFileSystem(window.PERSISTENT, 5*1024*1024, onSuccess, null);

而不是Cordova的实施:

window.requestFileSystem(LocalFileSystem.PERSISTENT, 5*1024*1024, onSuccess, null);

这对我有用,现在我有条件触发黑莓/其他的上述任何一种。希望它对你们有用,就像它对我一样。

干杯

相关问题