I'm trying to set a cookie programmatically but it's not working. The cookie gives the impression that it's valid. I then set it on the WKWebsiteDataStore.default().httpCookieStore
. In the asynchronous call back I then try to get all the cookies out of the store. However, my cookie isn't there. Where's it gone!?
let httpCookieStore = WKWebsiteDataStore.default().httpCookieStore
var cookieProperties = [HTTPCookiePropertyKey: Any]()
cookieProperties[.name] = "MarkCookie"
cookieProperties[.value] = "MarkValue"
cookieProperties[.domain] = "localhost"
cookieProperties[.maximumAge] = 1234
cookieProperties[.path] = "/"
let cookie = HTTPCookie(properties: cookieProperties)!
httpCookieStore.setCookie(cookie) {
// This is called fine. The cookie looks ok.
print("Cookie set \(cookie)")
DispatchQueue.main.async {
httpCookieStore.getAllCookies { cookies in
// This is empty!!!!
print(cookies)
}
}
}