我有很多 .pdf 格式的文件。我在 Collection View 中显示文件的名称。现在在 didSelectItemAtIndex 方法中,我想打开 Acrobat Reader 来打开 pdf 文件。我该如何实现? Acrobat Reader 是否还有 URL 方案,以便我可以检测该应用程序是否在手机上?
最佳答案
这是 Adobe reader 的应用程序架构:
com.adobe.Adobe-Reader
在 Swift 中,您可以执行以下操作:
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")
}
}
并在 plist 中添加以下应用架构。
<key>LSApplicationQueriesSchemes</key>
<array>
<string>com.adobe.Adobe-Reader</string>
</array>
关于ios - 如何打开Acrobat Reader阅读pdf文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45054749/