Display pdf from local file in webkit view

My app generates pdf files which I currently email to users for their records. I would like to display them in my app using WebKit View or perhaps PDFView.


Nothing I have tried works.


        do {
        let pdfFilename = "/var/mobile/Containers/Data/Application/BAF53A56-848D-48C0-ADF0-4DC1F945A3D1/Documents/myPDF.pdf"
            let url = NSURL(fileURLWithPath: pdfFilename)
     
            do{
            let data2 = try Data(contentsOf: url as URL)
            print(data2)
            let data = NSData(contentsOfFile: pdfFilename)!
webView.load(data, mimeType: "application/pdf", characterEncodingName:"", baseURL: pdfURL.deletingLastPathComponent())
                view.addSubview(webView)


data and data2 are empty and no webWiew is generated


I thought PDFKit might be an alternative. But

"A PDFView user interface element is available in Interface Builder, so you should use that wherever you want your application to display PDF content. Note that you need to install the PDF Kit palette in

/Developer/Extras/Palettes/PDFKit.palette
to make PDFViews available."


Searching the Apple Developer site and Xcode resources found no such palette.


What am I doing wrong this time?

Replies

The Apple documentation dates back to Xcode 3, where you could add Interface Builder classes to the palette. This was discontinued with the new Interface Builder in Xcode 4. However, the PDFView view class Interface Builder widget that was Extra in Xcode 3 is in the current Xcode Interface Builder palette. All the way down on the bottom.


Jonathan

On my Xcode 9.2 there is no PDFView widget. There is a View widget and a ContainerView widget.

at the bottom of the Object Library.