iOS13开始 WKWebView 去掉了cookie的自动推送功能,可以自己添加上。
代码如下:
if (@available(iOS 11.0, *)) {
NSArray *cookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies];
WKHTTPCookieStore *cookieStore = [WKWebsiteDataStore defaultDataStore].httpCookieStore;
if (cookies.count > 0) {
for (NSHTTPCookie *cookie in cookies) {
[cookieStore setCookie:cookie completionHandler:^{
}];
}
}
}
也可能是没有处理WKwebview打开新页面的问题,需要加上以下代码:
-
(void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {
if(navigationAction.targetFrame ==nil) {
[webView loadRequest:navigationAction.request];}
decisionHandler( WKNavigationActionPolicyAllow );
} (WKWebView *)webView:(WKWebView *)webView createWebViewWithConfiguration:(WKWebViewConfiguration *)configuration forNavigationAction:(WKNavigationAction *)navigationAction windowFeatures:(WKWindowFeatures *)windowFeatures {
if (!navigationAction.targetFrame.isMainFrame) {
[webView loadRequest:navigationAction.request];
}
return nil;
}
技术应用在 《悦览播放器》中,可在App Store中搜索查看。
————————————————
版权声明:本文为CSDN博主「XiaoDev」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/xiao562994291/article/details/103275675