美文网首页
WKWebView cooke 同步问题

WKWebView cooke 同步问题

作者: 李小威 | 来源:发表于2017-11-08 20:26 被阅读0次

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

    相关文章

      网友评论

          本文标题:WKWebView cooke 同步问题

          本文链接:https://www.haomeiwen.com/subject/muhqvttx.html