Reputation: 155
I want to display a local pdf file using UIDocumentInteractionController
Here is my code :
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)
the error is :
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.'
when i create a webWiew, the PDF is displayed well but i want to use pdf native viewer instead. Thanks for your help !
Upvotes: 1
Views: 1025
Reputation: 17372
This one always gets me too
let url : NSURL! = NSURL(string: urlpath!)
is wrong
you want
let url : NSURL! = NSURL.fileURLWithPath(urlpath!)
Upvotes: 2