有没有办法在Swift中手动设置cookie,在会话结束时不会过期? The docs说sessionOnly
应该默认为false,可以使用discard
属性设置,但它似乎对我不起作用。我试过了:
import Foundation
let cookie = HTTPCookie(properties: [
.domain: ".google.com",
.path: "/",
.name: "foo",
.value: "bar",
.discard: "FALSE"
])!
HTTPCookieStorage.shared.setCookie(cookie)
let cookies = HTTPCookieStorage.shared.cookies(for: URL(string: "https://google.com")!)
print(cookies)
// Optional([<NSHTTPCookie version:0 name:"foo" value:"bar" expiresDate:(null) created:2016-11-23 16:00:37 +0000 sessionOnly:TRUE domain:".google.com" partition:"none" path:"/" isSecure:FALSE>])
但如图所示,生成的Cookie的sessionOnly
值为true。
答案 0 :(得分:-1)
(static let discard:HTTPCookiePropertyKey =&#34; FALSE&#34;)应该基于Apple文档。