【问题标题】:Enabling webcache in WkWebview using WkWebView only(not with the help of NSURLRequest or NSURLSession)仅使用 WkWebView 在 WkWebview 中启用网络缓存(不借助 NSURLRequest 或 NSURLSession)
【发布时间】:2016-05-05 12:31:01
【问题描述】:

我知道我可以使用 NSURLRequest 启用缓存

  if reachability.isReachable {
             urlRequestCache=NSURLRequest(URL: url!, cachePolicy: NSURLRequestCachePolicy.UseProtocolCachePolicy, timeoutInterval: 10)
        }
        else {
            urlRequestCache = NSURLRequest(URL: url!, cachePolicy: NSURLRequestCachePolicy.ReturnCacheDataElseLoad, timeoutInterval: 60)
        }
       theWebView.loadRequest(urlRequestCache)

但我无法直接在 WkWebView 上找到任何方法来实现这一点。

【问题讨论】:

  • Cache for WKWebView的可能重复
  • @Vizllx - 这个问题是关于 NSURLRequest 或 NSURLSession 以及 WkWebView。但我的问题是如何仅使用 WkWebView 来实现

标签: ios caching browser-cache wkwebview offline-caching


【解决方案1】:

斯威夫特 4:

var webView = WKWebView()
if let url = URL(string: string) {
        var request = URLRequest(url: url)
        request.cachePolicy = .returnCacheDataElseLoad
        webView.load(request)
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-07-28
    • 1970-01-01
    • 2015-01-04
    • 1970-01-01
    • 1970-01-01
    • 2015-12-23
    • 2020-02-08
    • 2015-01-22
    相关资源
    最近更新 更多