美文网首页
WKWebview localstorage 存取信息不一致问题

WKWebview localstorage 存取信息不一致问题

作者: Coder_LRT | 来源:发表于2019-01-22 14:42 被阅读0次

UIWebview 存在内存泄露问题,iOS8以后,苹果推出了新框架Webkit,提供了替换UIWebView的组件WKWebView。

WKWebView 在内存占用上优化的很多。但是在实践中发现bug:localstorage信息不一致。

A页面和B页面都存在 一个WKWebView。 在B页面使用localstorage保存信息。 回到A页面取不到最新的数据。

原因:

<a href="https://developer.apple.com/reference/webkit/wkwebviewconfiguration"> wkwebviewconfiguration </a> 中有个属性 processPool,描述是:The process pool from which to obtain the view’s Web Content process.

解决方法:

把config中的processPool变为单例共享

+ (WKProcessPool*)singleWkProcessPool{

    staticWKProcessPool*sharedPool;

    staticdispatch_once_tonceToken;

    dispatch_once(&onceToken, ^{

        sharedPool = [[WKProcessPoolalloc]init];

    });

    returnsharedPool;

}

  WKWebViewConfiguration *config = [[WKWebViewConfiguration alloc] init];

  config.processPool = [NYWKWebView singleWkProcessPool];

  self.webView = [[WKWebView alloc]initWithFrame:CGRectZero configuration:config];

相关文章

网友评论

      本文标题:WKWebview localstorage 存取信息不一致问题

      本文链接:https://www.haomeiwen.com/subject/hoiljqtx.html