I am transitioning an app from UIWebView
to WKWebView
and there's an auto login feature that was handled by saving a cookie with the information that the user was authenticated into NSHTTPCookieStorage
. However WKWebView
does not seem to look at this location for the cookie and therefore the user is prompted with the login screen every time.
Is there something I need to activate to have the WKWebView use cookies properly?
The current app manages the users login / session outside of the webview and sets the cookies required for authentication into the the NSHTTPCookieStore . Unfortunately new WKWebView doesn't use the cookies from the NSHTTPCookieStorage .
WKWebView is an in-app browser that displays web content. It doesn't share cookies or web site data with other WKWebView instances, or with the Safari browser.
To check where are the app cookies stored on iPhone, On an iPhone, go to Settings -> Safari -> Advanced -> Website Data and you will see all cookies stored on your device. For iOS Application using web view The UIWebView will automatically store the cookies in the sharedHTTPCookieStorage.
Unlike UIWebView, which does not support server authentication challenges, WKWebView does. In practical terms, this means that when using WKWebView, you can enter site credentials for password-protected websites.
For now WKWebView and UIWebView does not co-work properly together, due to not sharing of same cookie storage space. It is been discussed in depth in following answer. How can I retrieve a file using WKWebView?
Lets hope Apple fix this in upcomming update.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With