Cordova 无法使用build.phonegap.com在IOS上运行文件API

Cordova 无法使用build.phonegap.com在IOS上运行文件API,cordova,phonegap-build,Cordova,Phonegap Build,我很难在iOS(iPhone)上使用build.PhoneGap.com文件API。我找了很多,但找不到原因。。。我希望有人能指出我做错了什么,或者能确认这是一个bug 我所做的: 以phonap中的代码示例为例 在config.xml中添加了文件和文件传输功能 将org.apache.cordova.file插件添加到config.xml 将IOSSpersistentFileLocation首选项添加到config.xml 压缩了这两个文件并将其上载到build.phonegap.

我很难在iOS(iPhone)上使用build.PhoneGap.com文件API。我找了很多,但找不到原因。。。我希望有人能指出我做错了什么,或者能确认这是一个bug

我所做的:

  • 以phonap中的代码示例为例

  • 在config.xml中添加了文件和文件传输功能

    
    

  • 将org.apache.cordova.file插件添加到config.xml

  • 将IOSSpersistentFileLocation首选项添加到config.xml

  • 压缩了这两个文件并将其上载到build.phonegap.com中的我的应用程序

  • 从我的iphone下载应用程序,然后运行它

  • 仅显示警报“onDeviceReady”

  • 插件似乎加载得很好,因为requestFileSystem方法已经定义。然而,gofFS回调从未被触发。我试过3.1.0和3.4.0 Cordova版本

    完整的软件包可以在这里下载:

    不要使用
    ondevicerady
    中的“try”和“catch”。失败回调处理错误。此代码应运行:

    document.addEventListener("deviceready", onDeviceReady, false);
    
    function onDeviceReady() {
        alert('onDeviceReady')
    
        window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
    }
    
    function gotFS(fileSystem) {
        alert('gotFS')
        fileSystem.root.getFile("readme.txt", null, gotFileEntry, fail);
    }
    
    function gotFileEntry(fileEntry) {
        alert('gotFileEntry')
        fileEntry.file(gotFile, fail);
    }
    
    function gotFile(file) {
        alert('gotFile')
        readDataUrl(file);
        readAsText(file);
    }
    
    function readDataUrl(file) {
        alert('readDataUrl')
        var reader = new FileReader();
        reader.onloadend = function (evt) {
            console.log("Read as data URL");
            console.log(evt.target.result);
        };
        reader.readAsDataURL(file);
    }
    
    function readAsText(file) {
        alert('readAsText')
        var reader = new FileReader();
        reader.onloadend = function (evt) {
            console.log("Read as text");
            console.log(evt.target.result);
        };
        reader.readAsText(file);
    }
    
    function fail(evt) {
        alert(evt.target.error.code);
    }
    

    非常感谢你!不知道try/catch确实改变了回调功能。
    document.addEventListener("deviceready", onDeviceReady, false);
    
    function onDeviceReady() {
        alert('onDeviceReady')
    
        window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
    }
    
    function gotFS(fileSystem) {
        alert('gotFS')
        fileSystem.root.getFile("readme.txt", null, gotFileEntry, fail);
    }
    
    function gotFileEntry(fileEntry) {
        alert('gotFileEntry')
        fileEntry.file(gotFile, fail);
    }
    
    function gotFile(file) {
        alert('gotFile')
        readDataUrl(file);
        readAsText(file);
    }
    
    function readDataUrl(file) {
        alert('readDataUrl')
        var reader = new FileReader();
        reader.onloadend = function (evt) {
            console.log("Read as data URL");
            console.log(evt.target.result);
        };
        reader.readAsDataURL(file);
    }
    
    function readAsText(file) {
        alert('readAsText')
        var reader = new FileReader();
        reader.onloadend = function (evt) {
            console.log("Read as text");
            console.log(evt.target.result);
        };
        reader.readAsText(file);
    }
    
    function fail(evt) {
        alert(evt.target.error.code);
    }