iOS Question how can I get the cookies in webview?

Discussion in 'iOS Questions' started by liulifeng77, Jul 24, 2015.

  1. liulifeng77

    liulifeng77 Active Member Licensed User

    In B4a, I can use CookieManager,but in b4i, I have no idea, anybody knows?
    regard!
     
  2. liulifeng77

    liulifeng77 Active Member Licensed User

    I try it like this, ,I can get the JSESSIONID,but can't get the sessionid.
    Dim no As NativeObject = wb
    log(no.RunMethod("stringByEvaluatingJavaScriptFromString:", Array("document.cookie"))

    why??
     

    Attached Files:

    • pi.PNG
      pi.PNG
      File size:
      2.8 KB
      Views:
      19
  3. Erel

    Erel Administrator Staff Member Licensed User

    You can use this code to get all the app cookies:
    Code:
    Sub WebView1_PageFinished (Success As Boolean, Url As String)
       
    Dim no As NativeObject
       
    Dim cookies As List = no.Initialize("NSHTTPCookieStorage").RunMethod("sharedHTTPCookieStorage"Null).RunMethod("cookies"Null)
       
    For Each cookie As NativeObject In cookies
         
    Log($"Name: ${cookie.GetField("name")}, value: ${cookie.GetField("value")}"$)
       
    Next
    End Sub
     
  4. liulifeng77

    liulifeng77 Active Member Licensed User

    great! thank you very much!
     
  5. liulifeng77

    liulifeng77 Active Member Licensed User

    something wrong with the code. Erel, why?
     

    Attached Files:

  6. Erel

    Erel Administrator Staff Member Licensed User

    Smart strings require B4i v2.00. Replace it with a regular string.
     
Loading...