使用Cordova/PhoneGap 3.3.0,我使用FileTransfer插件下载文件,然后尝试使用InAppBrowser插件打开它. 我可以成功下载文件,并将其放在临时目录中.由于File插件现在使用URL模式,我无法弄清楚如何将正确的url/path传递给window.open
InAppBrowser插件的方法.我也找不到任何相关文件.我能找到的所有"下载和打开"文档都是过时的和pre-URL-schema.
相关链接:
我发现过时的例子:
entry.fullPath
,现已弃用,toURL()
这是我的代码:
var uri = encodeURI("http://some.url/file.pdf");
window.requestFileSystem(LocalFileSystem.TEMPORARY, 0,
function (fileSystem) {
var fileTransfer = new FileTransfer();
var filename = fileSystem.root.toURL() + uri.substr(uri.lastIndexOf("/") + 1);
fileTransfer.download(uri, filename,
function(entry) { // download success
var path = entry.toURL(); //**THIS IS WHAT I NEED**
window.open(path, "_system");
},
function(error) {} // irrelevant download error
);
},
function(error) {} // irrelevant request fileSystem …
Run Code Online (Sandbox Code Playgroud) 尝试将我的PhoneGap javascript代码移植到Xcode中以便在iOS中进行调试.使用Cordova-3.0.0.
我打电话的时候:
navigator.connection.type
Run Code Online (Sandbox Code Playgroud)
我正在为navigator.connection获取一个'undefined'.
我没有在config.xml中正确包含网络连接插件,还是有其他不妥之处?是的,我包含了专门针对iOS的正确cordova.js文件.是的,设备已经被解雇了.
更新:我目前只在iOS模拟器上运行它.
我的config.xml:
<?xml version='1.0' encoding='utf-8'?>
<widget id="com.app.test" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>Hello Cordova</name>
<description>
Description
</description>
<author email="dev@callback.apache.org" href="http://cordova.io">
Apache Cordova Team
</author>
<access origin="*" />
<preference name="fullscreen" value="true" />
<preference name="webviewbounce" value="true" />
<plugins>
<plugin name="NetworkStatus" value="CDVConnection" />
</plugins>
</widget>
Run Code Online (Sandbox Code Playgroud)
谢谢您的帮助!