项目中Hybird容器升级到WKWebView各种坑

WKWebView 中localstorage不及时同步。processPool单例可以解决

class LocalstorageManger {
    static var sharePreferences = WKPreferences()
    static var shareProcessPool = WKProcessPool()
}
 let configuration = WKWebViewConfiguration()
 configuration.preferences = LocalstorageManger.sharePreferences
 configuration.processPool = LocalstorageManger.shareProcessPool

WKWebView 不支持 NSURLProtocol 坑

就不上代码了,具体请看简书和github的Demo如下

WKWebView 注册cookie,包含域名domain,时间expires等

let configuration = WKWebViewConfiguration()
let userContentController = WKUserContentController()
let cookieValue = String(format:"document.cookie ='platform=%@;path=/;domain=medlinker.com;expires=Sat, 02 May 2019 23:38:25 GMT;';document.cookie = 'sess=%@;path=/;domain=medlinker.com;expires=Sat, 02 May 2018 23:38:25 GMT;';",user.platform,user.sess)
let cookieScript = WKUserScript(source: cookieValue, injectionTime: .atDocumentStart , forMainFrameOnly: false) userContentController.addUserScript(cookieScript) 
configuration.userContentController = userContentController
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 转载链接:腾讯Bugly 导语 WKWebView 是苹果在 WWDC 2014 上推出的新一代 webView ...
    Jelly_沫阅读 2,871评论 0 3
  • 转载:http://www.cnblogs.com/NSong/p/6489802.html 导语 WKWebVi...
    李小威阅读 4,880评论 8 9
  • 导语 WKWebView 是苹果在 WWDC 2014 上推出的新一代 webView 组件,用以替代 UIKit...
    hope7th阅读 15,011评论 4 65
  • WKWebView 是苹果在 WWDC 2014 上推出的新一代 webView 组件,用以替代 UIKit 中笨...
    Aiana阅读 4,640评论 1 8
  • 马上就要考四级了,而我现在却想着学Linux,因为我身边的两个同学都在学习Linux,还时不时的发一些他们的笔记,...
    伪代码阅读 240评论 2 1