我发现文件插件不能工作。
我的函数如下:
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“成功,但fs.root.getFile不会触发成功/失败函数。我试着调试"CDVFile.m",我发现Objective-C代码已经被执行完了。
CDVFile.m中的getFile:
- (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 fail)。"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]);
};我的插件版本: 7.3 (带iOS SDK9.3)我的XCode版本: 6.5.0 Cordova -plugin-file4.3.2“文件”
我的config.xml添加了首选项:
<preference name="iosPersistentFileLocation" value="Library" />
<preference name="iosExtraFilesystems" value="library,library-nosync,documents,documents-nosync,cache,bundle,root" />有没有人遇到同样的问题,并解决了它?或者给我一些建议,谢谢!
2017-04-27补充说明:
The debug png why no callback fired
我知道为什么没有回调了。但是我不知道为什么是"succss and NO_RESULT"...
发布于 2017-05-02 15:20:58
几天前,我发现,因为另一个js文件冲突。如果我添加了js文件,文件插件就不能工作。我别无选择,只能在iframe页面中创建js文件。它现在可以工作了。也许你也有同样的问题,希望这能帮助到别人。
https://stackoverflow.com/questions/43606626
复制相似问题