Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where are an UIWebView's cookies stored?

Tags:

cookies

iphone

I'm building an iPhone app with cookies. Deleting cookies in the Safari settings doesn't delete them. Where are they stored? Is it possible to read them from another UIWebView?

Thanks!

like image 663
dot Avatar asked Apr 21 '09 07:04

dot


People also ask

Where are cookies stored C#?

Cookies is a small piece of information stored on the client machine. This file is located on client machines "C:\Document and Settings\Currently_Login user\Cookie" path. Its is used to store user preference information like Username, Password,City and PhoneNo etc on client machines.

Where are cookies stored iPhone apps?

To check where are the app cookies stored on iPhone, On an iPhone, go to Settings -> Safari -> Advanced -> Website Data and you will see all cookies stored on your device. For iOS Application using web view The UIWebView will automatically store the cookies in the sharedHTTPCookieStorage.

Does app Store have cookies?

Cookies also exist within apps when a browser is needed to view certain content or display an ad within an app. However, the cookies are completely “sandboxed” in apps. This means that cookies from one app cannot be shared with another app and that they remain private to each app.


2 Answers

Your application has its own "cookie jar" in the [NSHTTPCookieStorage sharedHTTPCookieStorage] container.

Here's how you might take a quick look at the cookies in your application's cookie jar:

NSHTTPCookie *cookie; NSHTTPCookieStorage *cookieJar = [NSHTTPCookieStorage sharedHTTPCookieStorage]; for (cookie in [cookieJar cookies]) {    NSLog(@"%@", cookie); } 

Several methods are available for filtering and manipulation. Take a look at the NSHTTPCookieStorage documentation for accessing cookies, and the NSHTTPCookie documentation for accessing individual cookie properties.

like image 195
Alex Reynolds Avatar answered Oct 19 '22 03:10

Alex Reynolds


Thanks for the pointer Alex! To add to this I will drop in my "cookie dumper" that I created using Alex's example. Maybe this will help someone else.

- (void) dumpCookies:(NSString *)msgOrNil { NSMutableString *cookieDescs    = [[[NSMutableString alloc] init] autorelease]; NSHTTPCookie *cookie; NSHTTPCookieStorage *cookieJar = [NSHTTPCookieStorage sharedHTTPCookieStorage]; for (cookie in [cookieJar cookies]) {     [cookieDescs appendString:[self cookieDescription:cookie]]; } NSLog(@"------ [Cookie Dump: %@] ---------\n%@", msgOrNil, cookieDescs); NSLog(@"----------------------------------"); }  - (NSString *) cookieDescription:(NSHTTPCookie *)cookie {  NSMutableString *cDesc      = [[[NSMutableString alloc] init] autorelease]; [cDesc appendString:@"[NSHTTPCookie]\n"]; [cDesc appendFormat:@"  name            = %@\n",            [[cookie name] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; [cDesc appendFormat:@"  value           = %@\n",            [[cookie value] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; [cDesc appendFormat:@"  domain          = %@\n",            [cookie domain]]; [cDesc appendFormat:@"  path            = %@\n",            [cookie path]]; [cDesc appendFormat:@"  expiresDate     = %@\n",            [cookie expiresDate]]; [cDesc appendFormat:@"  sessionOnly     = %d\n",            [cookie isSessionOnly]]; [cDesc appendFormat:@"  secure          = %d\n",            [cookie isSecure]]; [cDesc appendFormat:@"  comment         = %@\n",            [cookie comment]]; [cDesc appendFormat:@"  commentURL      = %@\n",            [cookie commentURL]]; [cDesc appendFormat:@"  version         = %d\n",            [cookie version]];  //  [cDesc appendFormat:@"  portList        = %@\n",            [cookie portList]]; //  [cDesc appendFormat:@"  properties      = %@\n",            [cookie properties]];  return cDesc; } 
like image 37
bladnman Avatar answered Oct 19 '22 03:10

bladnman