Loading Local PDF File Into WebView

后端 未结 3 759
栀梦
栀梦 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:55

    As posted by Anna Karenina above, "The device is case-sensitive. Make sure the filename matches exactly"

    0 讨论(0)
  • 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!
    }
    
    0 讨论(0)
  • 2021-01-06 08:04

    Are you sure you don't want to let the UIDocumentInteractionController do the heavy lifting for you?

    UIDocumentInteractionController *dc = [UIDocumentInteractionController interactionControllerWithURL:fileURL];
    dc.delegate = self;
    [dc presentPreviewAnimated:YES];
    
    0 讨论(0)
提交回复
热议问题