7

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)
            }
        }
    }
Mark Bridges
  • 7,606
  • 4
  • 43
  • 59
  • Is this still an issue with iOS 11.4? In my tests it was necessary to also specify the originURL, but my problem was somewhat different. – CWBudde Jun 11 '18 at 04:36

0 Answers0