Adding my own answer because I was running into a similar issue and this question came up in my search for solutions. The issue I was having is that the pdf would open in simulator fine but when I tried to open on a device it would just show a blank pdf page with the title of the pdf. I got an error saying something like "Couldn't issue file extension for path."
However, this is what I found:
Generating my url directly from the bundle would work for simulator but not devices
// This was not working on device, but did work with simulator
let fileURL = Bundle.main.url(forResource: "SomePDF", withExtension: "pdf")!
self.docVC = UIDocumentInteractionController(url: fileURL)
self.docVC.delegate = self
self.docVC.presentPreview(animated: true)
So just to see what would happen I took that same url, converted it to data and saved to a temporary directory with a new url. This ended up working:
// Now it opens correctly on both simulator and device
let url = Bundle.main.url(forResource: "SomePDF", withExtension: "pdf")!
let pdfData = try! Data(contentsOf: url)
let temp = NSTemporaryDirectory()
let fileURL = URL(fileURLWithPath: temp).appendingPathComponent("SomePDF.pdf")
try! pdfData.write(to: fileURL)
self.docVC = UIDocumentInteractionController(url: fileURL)
self.docVC.delegate = self
self.docVC.presentPreview(animated: true)
Hopefully this helps anyone else running into this issue. Was using iPhone X iOS 11.2.1