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信息