使用UIDocumentInteractionControllerDelegate显示本地pdf文件

时间:2015-06-02 14:05:13

标签: ios swift uidocumentinteraction

我想使用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 native viewer。谢谢你的帮助!

1 个答案:

答案 0 :(得分:2)

这个人总是让我

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

你想要

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