0

I have an iPhone app which is half web-based. I wanna check if a cookie is set (using Objective C) and do something else if it is not. I wanna check if a cookie with a specific name exists. Haven't found any solutions on this anywhere.

1 Answers1

0

First of all it is not clear what are you asking.

I'm assuming that you are what to check if cookie storage has some specific cookie. On iOS and OS X cookie storage is a singleton: NSHTTPCookieStorage. Now question how url should impact you check? For different urls you can have different cookie value with the same name.

Maybe you need something like this:

NSArray<NSHTTPCookie *> *cookies = NSHTTPCookieStorage.sharedHTTPCookieStorage.cookies;
cookies = [cookies filteredArrayUsingPredicate: [NSPredicate
    predicateWithFormat: @"name == %@", @"name"];

if (cookies.count > 0)
{
    …
}
Marek R
  • 32,568
  • 6
  • 55
  • 140