Cordova 无法使用build.phonegap.com在IOS上运行文件API
我很难在iOS(iPhone)上使用build.PhoneGap.com文件API。我找了很多,但找不到原因。。。我希望有人能指出我做错了什么,或者能确认这是一个bug 我所做的: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.
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);
}