Ios 未在UIDocumentInteractionController中打开PDF文件

Ios 未在UIDocumentInteractionController中打开PDF文件,ios,iphone,swift,Ios,Iphone,Swift,我正在模拟器上工作,没有像adobe这样的应用程序可以打开pdf文件……我正在使用UIDocumentInteractionController打开pdf文件,如下所示 let url=URL(fileURLWithPath: "/Users/sai/Library/Developer/CoreSimulator/Devices/425D8615-ADEC-4334-A639-C30B1E675EFA/data/Containers/Data/Application/AB3787BF-F6AC-

我正在模拟器上工作,没有像adobe这样的应用程序可以打开pdf文件……我正在使用UIDocumentInteractionController打开pdf文件,如下所示

let url=URL(fileURLWithPath: "/Users/sai/Library/Developer/CoreSimulator/Devices/425D8615-ADEC-4334-A639-C30B1E675EFA/data/Containers/Data/Application/AB3787BF-F6AC-4111-9847-A0FDC4E899F8/tmp/samplepdf.pdf")

    print("--------------------------------- str is \(url)")
    if (url != nil) {
        // Initialize Document Interaction Controller
        self.documentInteractionController = UIDocumentInteractionController(url: url)
        // Configure Document Interaction Controller
        self.documentInteractionController?.delegate = self
        // Preview PDF
        self.documentInteractionController?.presentOptionsMenu(from: self.view.frame, in: self.view, animated: true)
    }


  func documentInteractionControllerViewControllerForPreview(_ controller: UIDocumentInteractionController) -> UIViewController {
            return self
  }
我的屏幕显示如下

不确定是否有任何模拟器应用程序可以处理pdf文档-可能是新闻?但是,您只需将webView添加到视图控制器,并使用它来查看pdf

@IBOutlet weak var webView: UIWebView!
对url进行常规安全检查,然后:

webView.loadRequest(NSURLRequest(url: url as URL) as URLRequest)

我认为这是一个路径问题

替换

let url=URL(fileURLWithPath: "/Users/sai/Library/Developer/CoreSimulator/Devices/425D8615-ADEC-4334-A639-C30B1E675EFA/data/Containers/Data/Application/AB3787BF-F6AC-4111-9847-A0FDC4E899F8/tmp/samplepdf.pdf")

适用于Swift 3/Xcode 8

let url = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("samplepdf.pdf") as NSURL
希望这会有所帮助

let url = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("samplepdf.pdf") as NSURL