使用 UIDocumentInteractionControllerDelegate 显示本地 pdf 文件

display local pdf file using UIDocumentInteractionControllerDelegate

我想使用 UIDocumentInteractionController 显示本地 pdf 文件 这是我的代码:

pole = Pole.getWithMinor(minorBeacon)
    var address = pole.pdf

    if  pole != nil {
        var urlpath = NSBundle.mainBundle().pathForResource(pole.pdf, ofType: "pdf")
        let url : NSURL! = NSURL(string: urlpath!)
        //pdfView.loadRequest(NSURLRequest(URL: url))
        println(url)
        let docController = UIDocumentInteractionController(URL : url)
        docController.UTI = "com.adobe.pdf"
        docController.delegate = self
        docController.presentPreviewAnimated(true)

错误是:

2015-06-02 15:57:08.390 LePetitPoucet[4232:2026014] *** Assertion failure in -[UIDocumentInteractionController setURL:], /SourceCache/UIKit/UIKit-3318.93/UIDocumentInteractionController.m:1024
2015-06-02 15:57:08.391 LePetitPoucet[4232:2026014] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UIDocumentInteractionController: invalid scheme (null).  Only the file scheme is supported.'

当我创建一个 webWiew 时,PDF 显示得很好,但我想改用 pdf 本机查看器。感谢您的帮助!

这个总是让我着迷

let url : NSURL! = NSURL(string: urlpath!)错了

你想要

let url : NSURL! = NSURL.fileURLWithPath(urlpath!)