2017-04-25 96 views
0

我發現文件插件無法工作。Cordova-plugin-file getFile/getDirectory無回調失敗,誰可以幫我

我這樣的功能:

function (filename, fileObj, succCallback) { 
    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fs) { 
     fs.root.getFile(filename, {create: true, exclusive: false}, function(fileEntry){ 
      fileEntry.file(function (file) { 
       var reader = new FileReader(); 
       reader.onloadend = function() { 
        if(typeof succCallback === 'function') { 
         succCallback(this.result); 
        } 
       }; 
       reader.readAsText(file); 
      }, myfile.errorHandler); 
     }, errorHandler); 
    }, errorHandler); 
} 

功能做 「window.requestFileSystem」 SUCC,但fs.root.getFile不火的SUCC /失敗功能。 我嘗試調試「CDVFile.m」,我發現Objective-C代碼已經被exec了。

中的GetFile在 「CDVFile.m」:

- (void)getFile:(CDVInvokedUrlCommand*)command 
{ 
    NSString* baseURIstr = [command argumentAtIndex:0]; 
    CDVFilesystemURL* baseURI = [self fileSystemURLforArg:baseURIstr]; 
    NSString* requestedPath = [command argumentAtIndex:1]; 
    NSDictionary* options = [command argumentAtIndex:2 withDefault:nil]; 

    NSObject<CDVFileSystem> *fs = [self filesystemForURL:baseURI]; 
    CDVPluginResult* result = [fs getFileForURL:baseURI requestedPath:requestedPath options:options]; 


    [self.commandDelegate sendPluginResult:result callbackId:command.callbackId]; 
} 

如上所述,文件插件(源代碼 「DirectoryEntry.js」)succCallback(FUNC WIN)已不火,既不也不failCallback(FUNC失敗)。在 「DirectoryEntry.js」:

DirectoryEntry.prototype.getFile = function(path, options, successCallback, errorCallback) { 
    argscheck.checkArgs('sOFF', 'DirectoryEntry.getFile', arguments); 
    var fs = this.filesystem; 
    var win = successCallback && function(result) { 
     var FileEntry = require('./FileEntry'); 
     var entry = new FileEntry(result.name, result.fullPath, fs, result.nativeURL); 
     successCallback(entry); 
    }; 
    var fail = errorCallback && function(code) { 
     errorCallback(new FileError(code)); 
    }; 
    exec(win, fail, "File", "getFile", [this.toInternalURL(), path, options]); 
}; 

我的XCode版本:7.3(與iOS SDK 9.3) 我科爾多瓦版本:6.5.0 科爾多瓦 - 插件文件4.3.2 「文件」

我config.xml添加了首選項:

<preference name="iosPersistentFileLocation" value="Library" /> 
<preference name="iosExtraFilesystems" value="library,library-nosync,documents,documents-nosync,cache,bundle,root" /> 

有沒有人有同樣的問題,並解決它?或者給我一些提示,謝謝!

2017年4月27日的補充發言:

The debug png why no callback fired

我發現爲什麼沒有回調解僱。但我不知道爲什麼它是「succss和NO_RESULT」...

回答

0

前幾天,我發現,因爲另一個js文件衝突。如果我添加js文件,則文件插件無法工作。我別無選擇,只能在iframe頁面中創建js文件。它現在可以工作。 也許你有同樣的問題,希望這可以幫助別人。