0

I want to create a cookie with sessionOnly = False, and I understand that to do so it is necessary to set an expiry date. However, the expire date property is not set.

// set properties dictionary
NSMutableDictionary *cookieProperties = [NSMutableDictionary dictionary];

// insert all values
[cookieProperties setObject:@"myDomain" forKey:NSHTTPCookieDomain];
[cookieProperties setObject:@"myName" forKey:NSHTTPCookieName];
[cookieProperties setObject:@"/" forKey:NSHTTPCookiePath];
[cookieProperties setObject:@"myValue" forKey:NSHTTPCookieValue];
[cookieProperties setObject:@"FALSE" forKey:NSHTTPCookieDiscard];
[cookieProperties setObject:@"0" forKey:NSHTTPCookieVersion];

// setting expiry date for a month from now
[cookieProperties setObject:[[NSDate date] dateByAddingTimeInterval:2629743] forKey:NSHTTPCookieExpires];

// create a cookie with these properties
NSHTTPCookie *cookie = [NSHTTPCookie cookieWithProperties:cookieProperties];

When I look at cookieProperties value, I get:

{
    Discard = FALSE;
    Domain = myDomain;
    Expires = "2019-10-08 23:43:44 +0000";
    Name = myName;
    Path = "/";
    Value = myValue;
    Version = 0;
}

as it should.

But cookie value is:

<NSHTTPCookie
    version:0
    name:myName
    value:myValue
    expiresDate:'(null)'
    created:'2019-09-08 13:14:46 +0000'
    sessionOnly:TRUE
    domain:mydomain
    partition:none
    sameSite:none
    path:myPath
    isSecure:FALSE
 path:"myPath" isSecure:FALSE>

With expiresDate:'(null)' and sessionOnly:TRUE. Why is that?

Rotem Yakov
  • 181
  • 1
  • 12

1 Answers1

1

Turns out removing the line

[cookieProperties setObject:@"FALSE" forKey:NSHTTPCookieDiscard];

solved it.

This answer helped me, it said to remove this property and I thought setting it to false would be "stronger".

After running into it again I tried to actually remove it and that did it.

Rotem Yakov
  • 181
  • 1
  • 12