WKHTTPCookieStore没有检索集合Cookie。

时间:2018-02-28 18:44:53

标签: ios11 wkwebview nshttpcookie wkhttpcookiestore

我试图以编程方式设置Cookie,但它无效。 Cookie给人的印象是它有效。然后我将其设置在WKWebsiteDataStore.default().httpCookieStore上。在异步回调中,我尝试将所有cookie从商店中取出。但是,我的cookie不在那里。哪里去了!?

    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)
            }
        }
    }

0 个答案:

没有答案