WKWebView cooke 同步问题

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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容