如何多次调用httpCookieStore.getAllCookies,因为它似乎只能在模拟器上运行,而不是在实际设备上运行。
private var httpCookieStore: WKHTTPCookieStore {
return WKWebsiteDataStore.default().httpCookieStore
}
if #available(iOS 11.0, *) {
httpCookieStore.getAllCookies { (cookies) in
for cookie in cookies {
if let domain = domain {
if cookie.domain.contains(domain) {
cookieDict[cookie.name] = cookie.properties as AnyObject?
}
} else {
cookieDict[cookie.name] = cookie.properties as AnyObject?
}
}
completion(cookieDict)
}
} else {
// Fallback on earlier versions
}
由于某种原因,httpCookieStore仅被调用一次,而每隔一次在设备上不起作用,但在模拟器上则很好。