我发现文件插件无法工作。
我的功能是这样的:
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/fail 函数。我尝试调试“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失败)。“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) 我的 Cordova 版本:6.5.0 cordova-plugin-file 4.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 补充说明:</p>
我发现为什么没有触发回调。但我不知道为什么它是“succss and NO_RESULT”......