为了缩短开发周期。咱们尝试使用 用webview 加载html页面的方式,实现安卓、iOS开发的同步进行。html
UIWebview 存在内存泄露问题,iOS8之后,苹果推出了新框架Webkit,提供了替换UIWebView的组件WKWebView。web
WKWebView 在内存占用上优化的不少。可是在实践中发现bug:localstorage信息不一致。 A页面和B页面都存在 一个WKWebView。 在B页面使用localstorage保存信息。 回到A页面取不到最新的数据。缓存
##缘由:bash
wkwebviewconfiguration 中有个属性 processPool,描述是:The process pool from which to obtain the view’s Web Content process.app
##解决方法: 把config中的processPool变为单例共享框架
WKWebViewConfiguration *wkConfig = [[WKWebViewConfiguration alloc] init];
//使用单例 解决locastorge 储存问题
wkConfig.processPool = [hrWkWebViewController singleWkProcessPool];
_wkWebView = [[WKWebView alloc] initWithFrame:CGRectZero configuration:wkConfig];
+ (WKProcessPool *)singleWkProcessPool{
AFDISPATCH_ONCE_BLOCK(^{
sharedPool = [[WKProcessPool alloc] init];
})
return sharedPool;
}
复制代码
##疑惑 使用WKWebview 感受比 UIWebview 加载还慢一些。不知道是否是缓存的缘由。 求老哥们解答。优化