0

WKWebsiteDataStore.default().httpCookieStore.getAllCookies returns a different list of cookies from HTTPCookieStorage.shared.cookies. What is the difference between these two methods?

alekop
  • 2,838
  • 2
  • 29
  • 47

2 Answers2

2

HTTPCookieStorage.shared will be used with URLSession.shared network requests.

WKWebsiteDataStore.default() is used for WKWebView only. And the getAllCookies is asynchronous

Both are persistent.

Quang Vĩnh Hà
  • 494
  • 3
  • 8
0

The accepted answer is not entirely correct. Persistent cookies are shared between HTTPCookieStorage.shared and WKWebsiteDataStore.default(), though the sharing is not always immediate. Session cookies are not shared. This behavior doesn't seem to be documented by Apple anywhere, but is clearly evident if you run some tests. See this long thread for some related discussion:

Getting all cookies from WKWebView

jlew
  • 10,491
  • 1
  • 35
  • 58