1.基础使用
https://www.jianshu.com/p/5cf0d241ae12
2.js处理(可以兼容旧网页脚本,网页js不用改)
https://www.jianshu.com/p/7943f352d248
9.WKWebView 注册脚本方法,兼容之前项目中使用UIWebView
3.cookie处理
ios11版本解决方案(该方法适用于ios11版本之后)只需要添加这几行代码,问题完美解决
- (void)webView:(WKWebView *)webView decidePolicyForNavigationResponse:(WKNavigationResponse *)navigationResponse decisionHandler:(void (^)(WKNavigationResponsePolicy))decisionHandler {
NSArray *cookies = [NSHTTPCookieStorage sharedHTTPCookieStorage].cookies;
WKHTTPCookieStore *cookieStroe = webView.configuration.websiteDataStore.httpCookieStore;
for(NSHTTPCookie *cookie in cookies) {
[cookieStroe setCookie:cookie completionHandler:nil];
}
}
ios11以下
https://segmentfault.com/a/1190000020359208?utm_source=tag-newest
https://github.com/karosLi/KKJSBridge
如果网页登录后没有跳转(decidePolicyForNavigationResponse没调用),cookie没有成功保存,可以这样处理:手动进行一次跳转为了保证存储cookie成功。
4.goBack API问题
WKWebView 上调用 -[WKWebView goBack], 回退到上一个页面后不会触发window.onload()函数、不会执行JS。
解决:复制如下在本地js里面
//解决后退时无法重新调用js
window.onpageshow = function (e) {
if (e.persisted) {
window.location.reload(true)
}
}
5.项目全部替换完还有苹果警告邮件(可能还有第三方库没有改到)
ITMS-90809: Deprecated API Usage - Apple will no longer accept submissions of new apps that use UIWebView as of April 30, 2020 and app updates that use UIWebView as of December 2020. Instead, use WKWebView for improved security and reliability. Learn more (https://developer.apple.com/documentation/uikit/uiwebview).
第一步: cd到你的项目路径
第二步: 执行下面命令
grep -r UIWebView .
找到进行修改
网友评论