4

I am using a WKWebView inside my iOS app to display a remote website inside it. That site runs on ASP.NET platform.

When the site is loaded and after the user is logged in inside that remote website I am storing all cookies via following code:

+(void)saveHTTPCookies
{
    NSMutableArray *cookieArray = [[NSMutableArray alloc] init];
    for (NSHTTPCookie *cookie in [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies]) {
        [cookieArray addObject:cookie.name];
        NSMutableDictionary *cookieProperties = [NSMutableDictionary dictionary];
        [cookieProperties setObject:cookie.name forKey:NSHTTPCookieName];
        [cookieProperties setObject:cookie.value forKey:NSHTTPCookieValue];
        [cookieProperties setObject:cookie.domain forKey:NSHTTPCookieDomain];
        [cookieProperties setObject:cookie.path forKey:NSHTTPCookiePath];
        [cookieProperties setObject:[NSNumber numberWithUnsignedInteger:cookie.version] forKey:NSHTTPCookieVersion];
        [cookieProperties setObject:[[NSDate date] dateByAddingTimeInterval:2629743] forKey:NSHTTPCookieExpires];

        [[NSUserDefaults standardUserDefaults] setValue:cookieProperties forKey:cookie.name];
        [[NSUserDefaults standardUserDefaults] synchronize];

    }

    [[NSUserDefaults standardUserDefaults] setValue:cookieArray forKey:@"cookieArray"];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

i.e I am using NSHTTPCookieStorage sharedHTTPCookieStorage method to get the cookies loaded inside WkWebView.

I am having an issue with the cookies which are set "Session Only" inside the remote website. For example, take the case of .ASPXAUTH cookie which is being set as persistent if the user has set "remember me" option and if the user has set "remember me" as false, non persistent cookie is set.

The NSHTTPCookieStorage sharedHTTPCookieStorage method does not give non- persistent cookies in its collection. Is it a bug?

I went here https://stackoverflow.com/a/34190447 and found a similar issue with another user where he replied:

However, from my experiments, I found that Session cookies set by the server are not visible to NSHTTPCookieStorage.sharedHTTPCookieStorage().

Is there a way to get non-persistent cookies i.e the cookies which have no expiry set in NSHTTPCookieStorage?

Community
  • 1
  • 1
Raghav
  • 8,772
  • 6
  • 82
  • 106

0 Answers0