Is it possible to load local pdf file on SFSafariViewController?

后端 未结 1 816
旧巷少年郎
旧巷少年郎 2021-01-13 14:36

I tried with WKWebViewController, but still not working.

url = [[NSBundle mainBundle] URLForResource:@\"manual_eos_1d_x\" withExtension:@\"pdf\"];

WKWebView         


        
1条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-13 15:28

    It is not possible to show local pdf in SFSafariViewController, but it is possible to display it in a WKWebView. SFSafariViewController only support http and https schemes.

    From SFSafariViewController documentation:

    If your app lets users view websites from anywhere on the Internet, use the SFSafariViewController class. If your app customizes, interacts with, or controls the display of web content, use the WKWebView class.

    From SFSafariViewController init(url:) documentation:

    The URL must use the http or https scheme.

    To show local pdf file in WKWebView, you can do something similar to the following code:

        let mainBundle:Bundle = Bundle(for: WKWebContainerView.self)
        let path = mainBundle.path(forResource: "sample", ofType: "pdf")
        let pdfUrl = URL(fileURLWithPath: path!)
        let folderUrl = URL(fileURLWithPath: mainBundle.bundlePath, isDirectory: true)
        webView.loadFileURL(pdfUrl, allowingReadAccessTo: folderUrl)
    

    0 讨论(0)
提交回复
热议问题