How to set WKWebView cookie accept policy?

Hello,

I'm migrating my UIWebViews to WKWebWebViews and I'm not sure how to set the cookie accept policy. On a UIWebView, this policy was set via the NSHTTPCookieStorage as follows

[[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways];

or

[[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyNever];

but this has no effect on a WKWebView.

Where is the WebKit cookie storage and how can I set the cookie accept policies?

thanks

cheers,

Jan

I don’t think there’s a way to set this directly (the fact that UIWebView used

+sharedHTTPCookieStorage
was more of an historical accident than a specific design goal). However, iOS 9 introduces WKWebsiteDataStore which gives you a bunch of options here, although AFAICT none is the direct equivalent of
-setCookieAcceptPolicy:
.

If you can’t achieve you goal using the above, please file an enhancement request that describes your requirements. And if you do that, please post the bug number here, just for the record.

Share and Enjoy

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

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

ok so in otherwords a WKWebView will always accept cookies is that correct? That is the thing that matters to me.


cheers,

Jan

ok so in otherwords a WKWebView will always accept cookies is that correct?

Honestly, I don’t know. My guess is that it’ll do the standard default Apple thing (which on recent systems is

NSHTTPCookieAcceptPolicyOnlyFromMainDocumentDomain
) but if you rely on specific behaviour I recommend that you check it yourself.

I’d also appreciate you filing a bug requesting that this behaviour be documented. It seems like a significant omission.

If you do file any bugs here, please post your bug numbers, just for the record.

Share and Enjoy

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

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

Allright, I'll do that.


thanks

Hi JanC & Quinn,


Is there a radar ticket regarding this issue?

I am trying to track down why our (secure) iOS app's are not playing friendly when trying to share credentials between UIWebView's and WKWebView's. (OR even just NSURLSession's and WKWebViews). Any tips towards this end would be appreciated.

At the very least it would help me to know if there are known bugs in this area... from this thread I am starting to smell that impression...


We would LOVE to see a TN regarding this issue. Since 1) UIWebView's being less performant and 2) UIWebView's are not offering us the JavaScripting support we require.


Best from Switzerland,


|K<

Kent Clelland

Avaloq Evolution AG

Same problem here. I want to share cookies berween MKWebView and NSURLSession. Struggling to find a solution.

How to set WKWebView cookie accept policy?
 
 
Q