我想使用Phonegap [cordova 3.3.0]在IOS上使用文件。我阅读了如何访问文件并在API文档中读取手机间隙。这样使用Phonegap 3.3.0访问文件为ios
$ cordova plugin add org.apache.cordova.file
$ cordova plugin ls
[ 'org.apache.cordova.file' ]
$ cordova plugin rm org.apache.cordova.file
$ cordova plugin add org.apache.cordova.file-transfer
$ cordova plugin ls
[ 'org.apache.cordova.file',
'org.apache.cordova.file-transfer' ]
$ cordova plugin rm org.apache.cordova.file-transfer
功能gotFS还增加了插件(文件系统)后onDeviceReady()函数调用没有。
下面是我使用的代码:
function onDeviceReady() {
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
}
function gotFS(fileSystem) {
fileSystem.root.getFile("readme.txt", null, gotFileEntry, fail);
}
function gotFileEntry(fileEntry) {
fileEntry.file(gotFile, fail);
}
function gotFile(file){
readDataUrl(file);
readAsText(file);
}
function readDataUrl(file) {
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) {
var reader = new FileReader();
reader.onloadend = function(evt) {
console.log("Read as text");
console.log(evt.target.result);
};
reader.readAsText(file);
}
function fail(evt) {
console.log(evt.target.error.code);
}
此代码工作的机器人。但对于iOS,我得到的ReferenceError:找不到变量:LocalFileSystem 在这条线 -
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
你真的在监听deviceready事件来调用onDeviceReady函数吗?你有没有尝试在每一步添加console.log以确保所谓的或不是? – QuickFix
yes deviceready事件正在呼叫。 这行有一些问题 window.requestFileSystem(LocalFileSystem.PERSISTENT,0,gotFS,fail); – sudam
此代码适用于android。但对于Ios,我得到ReferenceError:无法找到变量:LocalFileSystem 在这一行 - window.requestFileSystem(LocalFileSystem。PERSISTENT,0,gotFS,失败); – sudam