ios - Swift - NSHTTPCookie is nil -
i trying write couple cookies in swift when display webview, able read cookies , react appropriately. found many examples of how create cookie , read apple docs can not seem valid nshttpcookie object. it's nil.
here's code:
let basehost = "domain.com" let oneyearinseconds = nstimeinterval(60 * 60 * 24 * 365) func setcookie(key: string, value: anyobject) { var cookieprops = [ nshttpcookieoriginurl: basehost, nshttpcookiepath: "/", nshttpcookiename: key, nshttpcookievalue: value, nshttpcookiesecure: "true", nshttpcookieexpires: nsdate(timeintervalsincenow: oneyearinseconds) ] var cookie = nshttpcookie(properties: cookieprops) // line fails due nil cookie nshttpcookiestorage.sharedhttpcookiestorage().setcookie(cookie!) }
my cookie
variable nil
. i've tried many combinations of properties including having both nshttpcookieoriginurl
, nshttpcookiedomain
, , without nshttpcookiesecure
, without nshttpcookieexpires
. nil
.
does have ideas i'm doing wrong?
i believe issue want using nshtttpcookiedomain
, not nshttpcookieoriginurl
.
could try properties so:
var cookieprops = [ nshttpcookiedomain: basehost, nshttpcookiepath: "/", nshttpcookiename: key, nshttpcookievalue: value, nshttpcookiesecure: "true", nshttpcookieexpires: nsdate(timeintervalsincenow: oneyearinseconds) ]
if not provide valid properties constructor, null value. should providing boolean nshttpcookiesecure
, not string.
Comments
Post a Comment