How to open Acrobat Reader to read pdf file?

邮差的信 提交于 2019-11-29 17:04:14
Fares Ben Hamouda

This is the app schema for Adobe reader :

com.adobe.Adobe-Reader

In Swift, you can do the following :

           var docController: UIDocumentInteractionController?
    if let path = Bundle.main.path(forResource: "PDF-NAME", ofType: "pdf") {
            let targetURL = NSURL.fileURL(withPath: path)
            docController = UIDocumentInteractionController(url: targetURL)
            let url = NSURL(string:"com.adobe.Adobe-Reader:");
            if UIApplication.shared.canOpenURL(url! as URL) {
                docController!.presentOpenInMenu(from: .zero, in: self.view, animated: true)
                print("Adobe-Reader")
            }else{
                print("Adobe-Reader is not installed")
            }
    }

And add below app schemas in plist.

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>com.adobe.Adobe-Reader</string>
</array>

First get the path for your pdf file. They call this to open pdf through acrobat reader

UIApplication.shared.open(URL(string: "com.adobe.adobe-reader://PDFFilePath")!)

But before that, there is no harm to confirm if the reader is already installed or not

if UIApplication.shared.canOpenURL(theURL! as URL) {

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