wkwebview 客户端和h5 cooke同步遇到了各种不成功的解决方案
最后选择把要缓存的信息直接通过js注入进去,一下时具体的示例代码:
//往web的cookers 里面添信息
WKWebViewConfiguration*config = [WKWebViewConfigurationnew];
NSString*cookers = [NSStringstringWithFormat:@"document.cookie = 'token=%@';document.cookie = 'UserId=%@';",@"token",@"123456789"];
WKUserContentController* userContentController =WKUserContentController.new;
WKUserScript* cookieScript = [[WKUserScriptalloc] initWithSource: cookers injectionTime:WKUserScriptInjectionTimeAtDocumentStartforMainFrameOnly:NO];
[userContentControlleraddUserScript:cookieScript];
[userContentControlleraddScriptMessageHandler:selfname:@"mzyxApp"];
config.userContentController= userContentController
WKWebView*webView= [[WKWebView alloc]initWithFrame:CGRectMake(0,0,[UIScreen mainScreen].bounds.size.width,[UIScreen mainScreen].bounds.size.height)configuration:config];
webView.navigationDelegate=self;
webView.scrollView.delegate=self;
webView.UIDelegate=self;
[self.viewaddSubview:webView];
完美解决native给H5加入cooke信息