UIDocumentInteractionController is not working with large pdf files with multiple pages.
Here in my code,
var docController:UIDocumentInteractionController!
...
DispatchQueue.main.async (execute: { [weak self] in
self?.docController = UIDocumentInteractionController(url: pdfFileURL!)
self?.docController.delegate = self
self?.docController.name = pdfFileURL?.lastPathComponent
self?.docController.presentPreview(animated: true)
})
and delegate method,
func documentInteractionControllerViewControllerForPreview(_ controller: UIDocumentInteractionController) -> UIViewController {
return self
}
This is the warning in console,
2017-05-26 12:46:51.178894 MyApp [3350:1136818] [default] View service did terminate with error: Error Domain=_UIViewServiceInterfaceErrorDomain Code=3 "(null)" UserInfo={Message=Service Connection Interrupted} #Remote
Below attached is the blank image,
Please help me out thanks.
Try Like This:
Declare : var interaction: UIDocumentInteractionController?
Then add
interaction = UIDocumentInteractionController(url: URL(string: "<PDF FILE PATH>")!)
interaction.delegate = self
interaction.presentPreview(animated: true) // IF SHOW DIRECT
OR if need any suggestion popup
interaction.presentOpenInMenu(from: /*<SOURCE BUTTON FRAME>*/, in: self.view, animated: true)
Implement Delegate -> UIDocumentInteractionControllerDelegate
public func documentInteractionControllerViewControllerForPreview(_ controller: UIDocumentInteractionController) -> UIViewController {
return self
}
public func documentInteractionControllerDidEndPreview(_ controller: UIDocumentInteractionController) {
interaction = nil
}
Be sure that your file is actually pdf file by checking its extension or if url path contains ".pdf"
Otherwise it will recognize it as text file and will not open it.
I just implemented UIDocumentInteractionController last week and it's working fine.
Do one thing declare as UIDocumentInteractionController as var
below to class
then do allocation and initialization in viewDidLoad()
as I did
documentInteractionController = UIDocumentInteractionController.init()
documentInteractionController?.delegate = self
and at the time of presenting I make it like this
documentInteractionController?.url = url
documentInteractionController?.presentPreview(animated: true)
Hope it will resolve your problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With