我有很多.pdf格式的文件。我在集合视图中显示文件的名称。现在在didSelectItemAtIndex方法中,我想打开Acrobat Reader来打开pdf文件。我该如何实现? Acrobat Reader也有一个URL Scheme,以便我可以检测该应用程序是否在手机上?
答案 0 :(得分:1)
首先获取pdf文件的路径。他们称之为通过acrobat reader打开pdf
UIApplication.shared.open(URL(string: "com.adobe.adobe-reader://PDFFilePath")!)
但在此之前,确认读卡器是否已经安装没有任何害处
if UIApplication.shared.canOpenURL(theURL! as URL) {
}
答案 1 :(得分:1)
这是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中添加以下app模式。
<key>LSApplicationQueriesSchemes</key>
<array>
<string>com.adobe.Adobe-Reader</string>
</array>