在iOS下使用InAppBrowser打开本地文件不起作用 [英] Opening a local file with InAppBrowser under iOS doesn't work

查看:329
本文介绍了在iOS下使用InAppBrowser打开本地文件不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Cordova开发移动应用程序.该应用程序允许用户使用一种文件管理器进行导航,并允许他们下载文件.我使用插件"FileTransfer"在用户设备上下载文件,然后调用InAppBrowser(0.5.2版)插件以将其打开.

I am developping a mobile application using Cordova. This application allows users to navigate in a kind of a file manager and allows them to download files. I use the plugin "FileTransfer" to download the file on the user's device and then call the InAppBrowser (version 0.5.2) plugin in order to open it.

虽然它在Android上确实很棒,但我不能在iOS(在版本7和8下进行测试)下说同样的话.

While it works really great under Android, I can't say the same under iOS (tested under versions 7 and 8).

这是我用来打开下载文件的代码行:

This is the line of code I use to open the downloaded file:

window.open(entry.toURL(), "_system");

在Android下,它会向用户建议他要启动哪个应用程序以打开文件,或根据文件扩展名自动启动默认应用程序.在iOS下,文件被下载,然后什么也没有发生.我发现当用户在iOS下时,我可以使用InAppBrowser插件的集成查看器.我这样做是这样的:

Under Android, it proposes the user which application he wants to launch to open the file or launches automatically the default application based on the file extension. Under iOS, the file is downloaded and then nothing happens. I have found out I could use the integrated viewer of the InAppBrowser plugin when the user is under iOS. I do that in this way:

if (navigator.userAgent.match(/iPhone|iPod|iPad/))
    window.open(entry.toURL(), "_blank");
else
    window.open(entry.toURL(), "_system");

使用这些代码行,如果用户在iOS下,则将启动集成查看器并显示文件.问题是ZIP文件或其他无法在查看器中呈现的文件.这个说加载错误".

With these lines of codes, if the user is under iOS, the integrated viewer is launched and displays the file. The problem is for ZIP files or other files that can't be rendered in the viewer. This one says "Load Error".

我认为,如果"_system"正常工作,Safari将会启动,并会向用户建议他如何打开文件.

I think that if "_system" worked, Safari would be launched and would propose the user how he wants to open the file.

有人知道如何使"_system"在iOS中工作吗?最终这是否是一个已知问题(我找不到与我的问题相关的任何东西)?

Does anybody have an idea of how I can make "_system" worked in iOS? Is this eventually a known problem (I couldn't find anything related to my problem)?

如果这可能与我的问题有关,那么我将使用Phonegap Build来生成.ipa文件.

If this can be relevant to my problem, I use Phonegap Build in order to generate the .ipa file.

推荐答案

在iOS上,当您使用_system时,它会尝试打开您通过Safari浏览器传递的网址. 由于iOS具有沙箱访问限制,因此Safari无法打开该网址,因为它位于您的应用沙箱中.

On iOS when you use _system, it try to open the url you pass with safari. As iOS have sandbox access limitations, safari can't open the url because it's inside your app sandbox.

您可以尝试使用该插件,它会提供一个打开方式"对话框,该对话框将向您显示支持您要打开的文件类型(如果有)的应用程序.

You can try this plugin, it provides an "open with" dialog that will show you the apps that support the type of file you want to open if any available.

https://build.phonegap.com/plugins/1076

这篇关于在iOS下使用InAppBrowser打开本地文件不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆