← Back to discussions

How are you handling cookies in Android and iOS WebView?

NNoopurPublished 6/27/2026478 views2 comments

We are experiencing an issue where users are logged out every time they close the app.
Our backend session cookies are set with HttpOnly and SameSite=Strict. On standard mobile browsers, the session persists, but inside the WebView container, it resets.

How do we ensure cookies are persisted properly on disk for both Android and iOS WebViews?

2 Comments

LLuke Lopez6/27/2026

On iOS, WKWebView uses a shared WKHTTPCookieStore. Sometimes iOS aggressively clears cookies for non-native domains. Make sure your server doesn't set cookies with the Session expiration type (which gets destroyed when the webview process terminates). Use an explicit Max-Age or Expires parameter on your set-cookie headers to force persistence on disk.

KKartik M6/27/2026

On Android, you need to enable cookie persistence explicitly in the WebView setup:

java
CookieManager.getInstance().setAcceptThirdPartyCookies(webView, true);
CookieManager.getInstance().flush();

Usually, Nativine handles this natively. Double check if your cookie lifetime is too short.

Please log in to reply.
WhatsApp