Swift:下载并打开pdf文件 [英] Swift: download and open pdf file

查看:507
本文介绍了Swift:下载并打开pdf文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对不起,如果这是一个愚蠢的问题,但是我没有找到答案:iPhone的默认pdf阅读器是什么?它是iBooks的所有iPhone?我问这个是因为在我的快速应用程序中,我想下载一个pdf文件,然后由设备的默认pdf阅读器(或其他应用程序)打开它。现在我可以用这样做:第一个是当点击下载按钮时,我让用户选择通过 UIDocumentInteractionController 下载文件的方式,然后他可以使用iBooks,文档,Chrome导入...我测试它,它的工作原理。第二种方法是在应用程序中下载文件(我从这个问题),然后用pdf阅读器打开它(如果可以的话,默认是本机的)。



有什么建议吗?

解决方案

网络,是否足以在浏览器中打开它?这将是一个简单的方法:

  if let url = URL(string:http://path.to/your .pdf){
UIApplication.shared.open(url)
}

Safari还提供了在另一个应用程序中打开文件的选项,如果用户想要使用其他应用程序。


Excuse me if it's a stupid question but I didn't find an answer: what's the default pdf reader in iPhone? Is it iBooks for all iPhones? I ask about this because in my swift application I want to download a pdf file then open it by the default pdf reader (or another application) of the device. Still now I can do that with to ways: the first is when the button "Download" is tapped, I let the user choose the way of downloading the file via UIDocumentInteractionController then he can import it using iBooks, Documents, Chrome... I tested it and it works perfectly. The second way is to download the file inside the application (I got the example from the answer of this question) then open it by a pdf reader (the default native one if this is possible).

Any suggestions please?

解决方案

If the PDF is available on the web, would it be enough to open it in the browser? This would be a trivially simple method:

if let url = URL(string: "http://path.to/your.pdf") {
    UIApplication.shared.open(url)
}

Safari also offers the option to open the file in another app, if the user wants to use something else.

这篇关于Swift:下载并打开pdf文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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