科尔多瓦requestFileSystem不再被加载3.4.1 [英] Cordova requestFileSystem is no longer being loaded 3.4.1

查看:162
本文介绍了科尔多瓦requestFileSystem不再被加载3.4.1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近更新到3.4.1科尔多瓦我然后继续构建和测试我的项目,发现它有问题。我花了最后一天半的时间试图恢复和重建项目,以便它的作品。没有什么迄今为止我已经尝试工作过。

I recently updated to Cordova 3.4.1 I then proceeded to build and test my project and found it had issues. I have spent that last day and a half trying to revert and rebuild the project so that it works. Nothing i have tried thus far has worked.

错误即时得到:

Uncaught TypeError: Object [object DOMWindow] has no method 'requestFileSystem'

用来生产这种误差

code:

Code used to produce this error:

var app = {
    appRoot: 'cdvfile://localhost/persistent/',
    init: function(){
        this.bindEvents();
    },
    bindEvents: function(){
        document.addEventListener('deviceready', this.onDeviceReady(this), false);
    },
    onDeviceReady: function(that){
        //location.reload(true);
        console.log(Object.keys(window));
        console.log(Object.keys(cordova));
        window.requestFileSystem(window.PERSISTENT, 0, function(fs){
            console.log('we have a fs');
            fs.root.getFile(dir+file,{create:true, exclusive: false},function(fileEntry){
                console.log('we have a file entry');
                var reader = new FileReader();
                reader.onloadend = function(evt){
                    success(evt.target.result);
                };
                reader.readAsText(dir+file);
            },fail);
        },fail);
    }
};
function fail(e){
    var msg = '';

    switch (e.code) {
      case FileError.QUOTA_EXCEEDED_ERR:
        msg = 'QUOTA_EXCEEDED_ERR';
        break;
      case FileError.NOT_FOUND_ERR:
        msg = 'NOT_FOUND_ERR';
        break;
      case FileError.SECURITY_ERR:
        msg = 'SECURITY_ERR';
        break;
      case FileError.INVALID_MODIFICATION_ERR:
        msg = 'INVALID_MODIFICATION_ERR';
        break;
      case FileError.INVALID_STATE_ERR:
        msg = 'INVALID_STATE_ERR';
        break;
      default:
        msg = 'Unknown Error';
        break;
    };

    console.log('Error: ' + msg);
 }

 app.init();

什么香港专业教育学院的尝试:

What Ive tried:


  • 香港专业教育学院使用以下科尔多瓦版本3.3.1,3.4.0,3.4.1,3.5.0
  • 尝试
  • 香港专业教育学院使用文件API 1.0.0,1.0.1,1.1.0
  • 的旧版本的尝试
  • 我曾尝试从头开始创建一个新的项目

  • 我一直在使用API​​版本17,19
  • 尝试建设
  • 我曾尝试在Android 4.2.2和4.4.2
  • 测试
  • Ive tried using the following Cordova versions 3.3.1, 3.4.0, 3.4.1, 3.5.0
  • Ive tried using older version of the file api 1.0.0, 1.0.1, 1.1.0
  • I have tried creating a new project from scratch
  • I have tried building using api version 17, 19
  • I have tried testing on an android 4.2.2 and 4.4.2

我已经验证插件加载到项目,它被内置到设备上。即时通讯使用 monitor.bat 随Android SDK的观赏控制台事件和错误和requestFileSystem是不被注入。

I have verified that the plugin is loaded into the project, and that it gets built onto the device. Im using the monitor.bat that comes with the Android SDK to watch console events and errors and the requestFileSystem is just not being injected.

我已经尝试使用(由<一的建议href=\"http://stackoverflow.com/questions/21283256/access-files-using-using-phonegap-3-3-0-for-ios\">here):

I have tried using( as suggested by here):

location.reload()

location.reload(true) //not from cache

要看看是否有与科尔多​​瓦插件初始化错误但没有什么。

to see if there was errors with the cordova plugin initialization but there was nothing.

有没有人有什么能解决这个问题的任何建议?

推荐答案

您实际上是调用 deviceReady 太快。在这一行:

You are actually calling deviceReady too soon. In this line:

document.addEventListener('deviceready', this.onDeviceReady(this), false);

onDeviceReady 返回结果的被传递给的addEventListener ,其中ISN ŧ你的意图,并表示它被调用任何插件初始化之前。

the return result of onDeviceReady is being passed to addEventListener, which isn't your intent, and means it gets called well before any plugins are initialized.

更好地做到这一点:

document.addEventListener('deviceready', this.onDeviceReady, false);

如果您的必须的通这个(或其他参数)一起,这样做:

If you must pass this (or another parameter) along, do this:

document.addEventListener('deviceready', this.onDeviceReady.bind(this), false);

但你不应该真的要做到这一点,假设你正确设置你的对象了。

But you shouldn't really have to do that, assuming you're setting your object up correctly.

这篇关于科尔多瓦requestFileSystem不再被加载3.4.1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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