Issue Displaying PDFs with UIDocumentInteractionController in iOS 11.2

Hi there,


I have an app which displays some locally-stored PDFs within the app using a UIDocumentInteractionController, but in iOS 11.2, instead of showing the content of the PDF, it just shows a grey screen with the title of the file. This has been working fine for years, but in the latest beta I can see this message in the console:


"

[default] Couldn't issue file extension for url: [FILENAME] #PreviewItem

"


I don't see anything in the release notes to suggest that this would have changed? It still works in the simulator, but not on real devices.



The code to present the PDF looks like this:


NSURL *url = [NSURL fileURLWithPath:filePath];

self.documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:url];

[_documentInteractionControllersetDelegate:self];

[_documentInteractionController presentPreviewAnimated:YES];


Any advice or suggestions are appreciated, thanks!


Adam

Accepted Reply

We have the same issue here with iOS 11.2 release version.

Solved it for now by copying the file to a temp file in documents directory before displaying it.

Replies

We have the same issue here with iOS 11.2 release version.

Solved it for now by copying the file to a temp file in documents directory before displaying it.

I can also confirm that copying to documents folder resolved this issue for us too.

I also have this issue... 😟

Tengo el mismo problema y no veo una solución o una respuesta de parte de apple ¿que ocurre?.


La app de DropBox tiene esta misma funcionalidad, muestra de forma correcta los documentos y permite abrirlos.

¿Que es lo que se debe corregir?


El siguiente codigo mostraba de forma correcta la vista previa de los documentos..., ahora ya solo muestra una pantalla gris.


/

/

/

/

/

/

/

import UIKit

class DetalleViewController:UIViewController,UIDocumentInteractionControllerDelegate{

var iForma:Forma!{

didSet(nuevaForma){

self.actualizaUI()

}

}

@IBOutlet weak var descripcionLabel :UILabel!

@IBOutlet weak var detalleTextView :UITextView!

@IBOutlet weak var archivoBotton :UIButton!

@IBOutlet weak var tipoArchivoLabel :UILabel!

@IBOutlet weak var escudoImageView :UIImageView!

@IBOutlet weak var pieView: UIView!

override func viewDidLoad(){

super.viewDidLoad()

pieView.layer.masksToBounds = true

pieView.layer.cornerRadius = 10

actualizaUI()

}

override func viewWillAppear(_ animated:Bool){

archivoBotton.setTitle(" " + iForma.iNombreArchivo + "." + iForma.iExtension,for:.normal)

archivoBotton.setImage(iForma.iconoArchivo(aTipo:"B"),for:.normal)

}

override func didReceiveMemoryWarning(){

super.didReceiveMemoryWarning()

}

/

@IBAction func PreVisualizarForma(_ sender:UIButton){

self.leerArchivoUsandoInteractionControlle()

}

/

func actualizaUI(){

descripcionLabel?.text = iForma.iDescripcion

detalleTextView?.text = iForma.iDetalle

tipoArchivoLabel?.text = iForma.iTipoArchivo

if let lArchivoBotton = archivoBotton {

lArchivoBotton.setTitle(" " + iForma.iNombreArchivo + "." + iForma.iExtension,for:.normal)

lArchivoBotton.setImage(iForma.iconoArchivo(aTipo:"B"),for:.normal)

}

}

/

func leerArchivoUsandoInteractionControlle(){

let lBUndle = Bundle.main

let lPath = lBUndle.path(forResource:iForma.iNombreArchivo,ofType:iForma.iExtension)

let lDocInteractionController = UIDocumentInteractionController(url:NSURL(fileURLWithPath:lPath!) as URL)

lDocInteractionController.delegate = self

lDocInteractionController.presentPreview(animated:true)

}

/

func documentInteractionControllerViewControllerForPreview(_ controller:UIDocumentInteractionController) -> UIViewController{

return self

}

/

}

I can confirm that I am having the same issue with the PDFs not displaying on the device.


What do you mean by copying to the documents folder, how can I replicate your success?

Thanks a lot.

Yup, we see this in our released apps on iOS 11.2.1 in the QLPreviewController also.

By using the share button in the QLPreviewController I can upload it to Files, insert in into Notes or a mail, but not open the PDF in iBooks or Acrobat reader...

It looks like there is some issue here with referencing a document from the apps bundle since files downloaded to the temp dir will display as usual. But it's not like it doesn't have access to the file since it can share it?


Have someone radar'ed this bug?

I also see this behavior in all current versions of 11.2 (the latest being 11.2.5). However, it does appear fixed in the 11.3 beta, so there's some hope. For now, I'd follow the recommendations above (re: copying to documents) or just switching to WKWebView if you don't need the share sheet functionality from the document preview controller.