Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Couldn't issue file extension for URL

I am stuck and don't know what to do. I want to be able to display PDF's within my application using QuickLook. I have imported my PDF files into my project and am using the code below to display it.

    func previewController(_ controller: QLPreviewController, previewItemAt index: Int) -> QLPreviewItem {
    //let bundle = Bundle.main
    let resourcePath = Bundle.main.resourceURL!.appendingPathComponent("Manuals/\(nodeName).pdf").path
    //let path = resourcePath + bundle.path(forResource: nodeName, ofType: "pdf")!
    let url = URL(fileURLWithPath: resourcePath)
    return url as QLPreviewItem
}

The URL which is generated is

"file:///var/containers/Bundle/Application/3923DC1F-386E-4038-A8B1-A855483F4C06/Application%20v1.app/Manuals/CYB.pdf"   

The error I'm getting is

Couldn't issue file extension for url: file:///var/containers/Bundle/Application/3923DC1F-386E-4038-A8B1-A855483F4C06/Application%20v1.app/Manuals/CYB.pdf #PreviewItem

and on the display Im just getting a grey screen with the name of the file and PDF Document under it. Does anybody know what Im doing wrong. I have tired to google the answer but either the solution did not work for me or the answer is outdated.

Any help would be great. If there is anymore information you might need let me know and I can provide that.

Thanks

like image 209
GBSingh Avatar asked Jan 03 '23 12:01

GBSingh


2 Answers

Thanks for everybody who gave their inputs with this issue. I have finally fixed it. It turns out that it was nothing to do with the code that I posted but due to my iPad not running iOS 11.3. For some reason this issue occurs on 11.2.x but got fixed in 11.3. I don't know why I didn't update earlier but its finally working. Hopefully anybody else having this issues finds this useful and doesn't waste a full day trying to figure out why it doesn't work.

Thanks once again.

like image 112
GBSingh Avatar answered Jan 05 '23 18:01

GBSingh


To access a file inside a folder in main Bundle , drag the folder named Manuals to project xcode and select create references folder

enter image description here

//

enter image description here

then access the resource with

let fileUrl = Bundle.main.url(forResource:\(nodeName) ,withExtension:"pdf",subdirectory: "Manuals")  
like image 30
Sh_Khan Avatar answered Jan 05 '23 16:01

Sh_Khan