美文网首页
WKWebView、UIWebView设置localStorag

WKWebView、UIWebView设置localStorag

作者: IT小妞儿 | 来源:发表于2016-07-04 18:04 被阅读7890次
    • WKWebView设置localStorage
    NSString * userContent = [NSString stringWithFormat:@"{\"token\": \"%@\", \"userId\": %@}", @"a1cd4a59-974f-44ab-b264-46400f26c849", @"89"];
    // 设置localStorage
    NSString *jsString = [NSString stringWithFormat:@"localStorage.setItem('userContent', '%@')", userContent];
    // 移除localStorage
    // NSString *jsString = @"localStorage.removeItem('userContent')";
    // 获取localStorage
    // NSString *jsString = @"localStorage.getItem('userContent')";
    [self.webView evaluateJavaScript:jsString completionHandler:nil];
    
    • UIWebView设置localStorage
    NSString * userContent = [NSString stringWithFormat:@"{\"token\": \"%@\", \"userId\": %@}", @"a1cd4a59-974f-44ab-b264-46400f26c849", @"89"];
    // 设置localStorage
    NSString *jsString = [NSString stringWithFormat:@"localStorage.setItem('userContent', '%@')", userContent];
    // 移除localStorage
    // NSString *jsString = @"localStorage.removeItem('userContent')";
    // 获取localStorage
    // NSString *jsString = @"localStorage.getItem('userContent')";
    [self.webView stringByEvaluatingJavaScriptFromString:jsString];
    

    相关文章

      网友评论

          本文标题:WKWebView、UIWebView设置localStorag

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