Swift:下载并打开pdf文件 [英] Swift: download and open pdf file
问题描述
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屋!