使用sessionOnly设置cookie:False

时间:2016-11-23 16:09:19

标签: swift http cookies

有没有办法在Swift中手动设置cookie,在会话结束时不会过期? The docssessionOnly应该默认为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。

1 个答案:

答案 0 :(得分:-1)

(static let discard:HTTPCookiePropertyKey =&#34; FALSE&#34;)应该基于Apple文档。