iOS Question How to get cookies from WKWebView

ergonous

New Member
Licensed User
Longtime User
Hi,

I wanted to get cookies from WKWebview.

First i tried to use the suggested method for normal WebViews


B4X:
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

but the return was Null.

I also tried to get the cookies using js ("document.cookie"), but the returned cookies, were only a portion, due to HttpOnly restrictions.

Is there any possible way to get all the cookies from a WKWebview?
 
Last edited:

ergonous

New Member
Licensed User
Longtime User
Unfortunately I cant use standard WebView, because for the needs of my App to reach a specific Url and make an HTTP request, i have to inject js code and i need the cookies too...

Thanks Erel for the replied link!
 
Upvote 0

watesoft

Active Member
Licensed User
Longtime User
Unfortunately I cant use standard WebView, because for the needs of my App to reach a specific Url and make an HTTP request, i have to inject js code and i need the cookies too...

Thanks Erel for the replied link!
Sorry, I want to ask you, how do you use httpserver in IOS, I need to use local service and make an HTTP request. Thank you!
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…