【问题标题】:Why WKWebView is not loading pdf in iOS using swift?为什么 WKWebView 不使用 swift 在 iOS 中加载 pdf?
【发布时间】:2020-12-23 12:52:29
【问题描述】:

我正在使用 WKWebView 从 web url 预览文件,但有些 url 已打开,有些未打开。我不知道发生这种情况的原因,网址看起来相同,但是未在 WKWebView 中加载的网址是在 safari 中下载而不是打开。

工作网址: https://test.store.digiboxx.com:9000/9d2830d7cdec4de2/mayavati/413780_2CB2E888-CCE2-474D-8549-00270F92C6F0_New_pfd.pdf?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=asdklhfgdefyu%2F20201220%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20201220T131747Z&X-Amz-Expires=604800&X-Amz-SignedHeaders=host&X-Amz-Signature=204841a52ddfc4d003f4b0bea45488b45a347fcd8e694011c9de4680afcebe9c

有问题的网址:https://test.store.digiboxx.com:9000/9d2830d7cdec4de2/mayavati/F6685A44-E65F-4A6F-9E8A-34DA333C3E2F_New_pfd.pdf?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=asdklhfgdefyu%2F20201220%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20201220T131840Z&X-Amz-Expires=604800&X-Amz-SignedHeaders=host&X-Amz-Signature=85efaa80b4e53a47869c82b4dbe64c9bfa6417991184abf69891d71a19a986a9

webView = WKWebView(frame: otherDocumentView.bounds, configuration: WKWebViewConfiguration())
        self.webView.navigationDelegate = self
        webView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
        self.otherDocumentView.addSubview(webView)
        let myRequest = NSURLRequest(url: NSURL(string: fileURL)! as URL)
        webView.load(myRequest as URLRequest)

【问题讨论】:

  • 当您在 Chrome 浏览器中单击 URL 时会发生同样的差异,因此它可能更多地与 Web 服务器响应它们的方式有关,而不是与 WKWebView 相关。
  • 你为什么不使用PDFView

标签: ios swift wkwebview


【解决方案1】:
if let pdf = NSBundle.mainBundle().URLForResource("myPDF", withExtension: 
"pdf", subdirectory: nil, localization: nil)  {
            let req = NSURLRequest(URL: pdf)
            let webView = UIWebView(frame: CGRectMake(20,20,self.view.frame.size.width-40,self.view.frame.size.height-40))
            webView.loadRequest(req)
            self.view.addSubview(webView)
        }

【讨论】:

    猜你喜欢
    • 2021-12-27
    • 1970-01-01
    • 2019-12-27
    • 1970-01-01
    • 2019-01-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-09
    相关资源
    最近更新 更多