Cache for WKWebView

后端 未结 2 1171
臣服心动
臣服心动 2021-01-04 05:02

I am having trouble with my custom internet browser. I am using WKWebView. I have tabs in my app. If I click on a tab new NSURLRequest loads in the WKWebView. I need to impl

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-04 05:21

    I typically will load from a server if I have internet connectivity. Otherwise, I load from the cache.

     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)
    

提交回复
热议问题