WKWebView session logout issue

In my app, I want to do login using WKWebView and then all further request to server is done.

I'm able to perform successful login using WKWebView. On it's success I get session information. I had implemented it previously using UIWebView and it was working properly. All my further web service call were working fine in UIWebView.

Now when I implemented login with WKWebView it is successfully login but when i hit different link (URL) it gives me logout response every time and I'm trying to call service using Cookies and , it's not giving me proper response as session information are not being passed.

Is there any way, I can store those session information of WKWebView

Any help will be appreciated. Please help!

To clarify, you’re using WKWebView to do the login but you then want to make a request to a web service (using NSURLSession perhaps) using that login?

If so, the reason you’re running into problems is that WKWebView does all of its networking out of process, so your NSURLSession code does not directly see the cookies that it acquired. One way to make this work is to grab the relevant cookies from the web view (via WKWebsiteDataStore) and manually apply them to your NSURLRequest. WKWebsiteDataStore lets you see and delete such cookies, but it does not let you get them. You can, however, run JavaScript within the web view (using

-evaluateJavaScript:completionHandler:
) to get the relevant cookie (using
document.cookie
) and then manually apply it to your NSURLRequest.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

raza08, can you please share your code how you performing login with WKWebView?


Thanks.

WKWebView session logout issue
 
 
Q