我有一个Phonegap应用,我试图将文件保存到设备的存储空间,但是我在config.xml文件中包含插件cordova-plugin-file
之后,cordova.file
对象仍未定义。我正在使用clg cli-6.5.0
使用Phonegap Build构建应用程序。
使用Chrome检查器工具,我可以看到,当我尝试记录cordova.file
对象时,它返回undefined,logging cordova
会返回日志中的cordova对象。
以下是来自控制台的日志,如上所述:
以下行位于我的config.xml文件中:
<plugin name="cordova-plugin-file" source="npm" />
<preference name="iosExtraFilesystems" value="library,library-nosync,documents,documents-nosync,cache,bundle,root" />
<preference name="AndroidExtraFilesystems" value="files,files-external,documents,sdcard,cache,cache-external,assets,root" />
<preference name="AndroidPersistentFileLocation" value="Compatibility" />
这是我用来保存文件的代码:
window.resolveLocalFileSystemURL(cordova.file.externalRootDirectory, function(dir) {
console.log("Creating file");
var fileName;
do {
fileName = prompt("Please enter a name for your file", "");
} while(fileName == null || fileName == "");
dir.getFile(fileName, {create:true}, function(file) {
console.log("File created succesfully");
file.createWriter(function(fileWriter) {
console.log("Writing content to file");
fileWriter.write(imageBlob);
}, function(){
console.log('Unable to save file');
});
});
});
但是此功能永远不会运行,我也无法通过Chrome检查工具查看控制台中的任何日志。 imageBlob
是一个Blob对象,包含一个转换为Blob对象的base64图像,但代码永远不会达到。
我还使用config.xml文件中的spec
属性尝试了旧版本的插件,但这不起作用。
答案 0 :(得分:0)
一些想法:
答案 1 :(得分:0)
我只是遇到了这个问题,在检查了phonegap的构建日志后,我发现我的cordova-plugin-file
版本需要更新的phonegap版本,需要将其设置为:
<preference name="phonegap-version" value="cli-8.0.0" />
http://docs.phonegap.com/phonegap-build/configuring/preferences/#phonegap-version