我在iOS(iPhone)上无法与build.PhoneGap.com一起使用文件API时遇到麻烦。我进行了很多搜索,但是我找不到原因...我希望有人指出我做错了什么,或者可以确认这是一个错误?
我做了什么:
从phonap文档中获取了代码示例
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
alert('onDeviceReady')
try
{
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
}
catch (err)
{
alert(err);
}
}
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);
}
在config.xml中添加了文件和文件传输功能
<feature name="File"> <param name="ios-package" value="CDVFile" /> </feature> <feature name="FileTransfer"> <param name="ios-package" value="CDVFileTransfer" /> </feature>
在config.xml中添加了org.apache.cordova.file插件
<gap:plugin name="org.apache.cordova.file" version="1.0.1" />
在config.xml中添加了iosPersistentFileLocation首选项
<preference name="iosPersistentFileLocation" value="Compatibility" />
压缩两个文件并将其上传到build.phonegap.com中的我的应用程序中
从我的iPhone下载该应用,然后运行
仅显示警报“ onDeviceReady”
由于定义了requestFileSystem方法,因此插件似乎可以很好地加载。但是,永远不会触发gofFS回调。我已经尝试了3.1.0和3.4.0 Cordova版本。
完整的软件包可以在这里下载:https : //www.dropbox.com/s/03228h72ygvf5jg/phonegap%20file%20api.zip
请勿在中使用“ try”和“ catch” onDeviceReady
。失败回调处理错误。此代码应运行:
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);
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句