问题描述
我创建了一个Web应用程序,我需要将其转换为移动应用程序,现在我所拥有的只是html5/js/css文件,这意味着我没有任何www foder没有平台文件夹,没有cordova项目...我首先开始使用cordova命令行构建应用程序,但是我没有,发现很多问题,然后使用 https://build.phonegap.com/,对我来说很好.为了读取文件,我尝试了以下代码:
I created a web application that I need to convert to a mobile application, now all I have is html5/js/css files which means I don't have any www foder no platforms folder, not a cordova project ... I started first to build the app using cordova command lines, but I couldn't, I found many problems on that, I used then https://build.phonegap.com/ , and it works fine for me. In order to read the file, I have tried this code :
window.resolveLocalFileSystemURI("file:///android_asset/www/data/User.xml", function () {
alert("Success");
}, function () {
alert(" error ");
});
但是,它没有用.我添加了try catch
,例外是:
but, it didn't work. I added a try catch
, the exception was :
window.resolveLocalFileSystemURI is not a function
我需要在代码中添加一些内容才能使其正常工作吗?
Do i need to add something to my code to make it work ?
推荐答案
您需要安装一个插件才能正常工作.
You need to install a plugin for this to work.
基本上,在应用程序的根目录中运行"cordova plugin add org.apache.cordova.file".
Basically, run "cordova plugin add org.apache.cordova.file" at your application's root directory.
有关详细说明,请参见访问功能"下的此处: http://docs.phonegap.com/zh-CN/edge/cordova_file_file.md .html#LocalFileSystem
For detailed instructions see here, under "Accessing the Feature":http://docs.phonegap.com/en/edge/cordova_file_file.md.html#LocalFileSystem
UPDATE 2019
添加此插件的正确方法现在是在项目根目录中使用以下命令:
The correct way to add this plugin is now with this command in your project root:
cordova plugin add cordova-plugin-file
这是一个核心的cordova插件. 在npm上找到文件
This is a core cordova plugin. Documentation found here on npm
这篇关于window.resolveLocalFileSystemURI不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!