Loading Local PDF File Into WebView

后端 未结 3 758
栀梦
栀梦 2021-01-06 07:23

I am attempting to put the following functionality into an iOS app I am writing:

  • Ship a set of PDFs in the resources folder of the project in XCode
  • Co
3条回答
  •  北海茫月
    2021-01-06 07:58

    As bshirley suggested UIDocumentInteractionController is a great option to present your PDF. Initially I tried using the 3rd party JSQWebViewController but I was getting a blank screen on device while on simulator it was working. UIDocumentInteractionController worked great for me! For Swift you can do:

    let interactionController = UIDocumentInteractionController(url: fileURL)
    interactionController.delegate = self
    interactionController.presentPreview(animated: true)
    

    and implement the delegate method:

    // Mark: UIDocumentInteractionControllerDelegate
    func documentInteractionControllerViewControllerForPreview(_ controller: UIDocumentInteractionController) -> UIViewController {
        return UIApplication.shared.keyWindow!.rootViewController!
    }
    

提交回复
热议问题