Opening a local file with InAppBrowser under iOS doesn't work

吃可爱长大的小学妹 提交于 2019-12-23 02:38:31

问题


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.

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");

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");

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".

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

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)?

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


回答1:


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



来源:https://stackoverflow.com/questions/26377829/opening-a-local-file-with-inappbrowser-under-ios-doesnt-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!