美文网首页
wkwebview 设置coolie

wkwebview 设置coolie

作者: writeSpace | 来源:发表于2025-04-16 18:07 被阅读0次
let userContentController:WKUserContentController  = WKUserContentController()

        let cookieSource:String =  """

document.cookie = 'userInfo=\(userInfoStr);'
        
"""
        let cookieUserIdSource:String = """
        document.cookie = 'USERID=\(userId);'
        """
        print("cookieSource=\(cookieSource)");
        //        String  [NSString stringWithFormat:@"document.cookie = 'user=%@';", @"userValue"];
        let cookieScript:WKUserScript = WKUserScript.init(source: cookieSource, injectionTime: .atDocumentStart, forMainFrameOnly: false)
        let cookieUserId:WKUserScript = WKUserScript.init(source: cookieUserIdSource, injectionTime: .atDocumentStart, forMainFrameOnly: false)
        userContentController.addUserScript(cookieScript)
        userContentController.addUserScript(cookieUserId)
        userContentController.addUserScript(WKUserScript.init(source: "document.cookie = 'from=app;'", injectionTime: .atDocumentStart, forMainFrameOnly: false))
        
        controller = userContentController;

设置cookie wkwebview

相关文章

网友评论

      本文标题:wkwebview 设置coolie

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