Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Private browsing with UIWebView on the iPhone & iPad

How do existing apps implement this feature???

Can I store cookie only for certain sites, and only inside my app? It's my understand that the web view stores cookies in shared mode...so that they are shared with Safari and other apps that use UIWebView.

like image 325
devguy Avatar asked Jan 21 '23 22:01

devguy


1 Answers

According to the NSHTTPCookieStorage docs, cookies are not shared between applications:

iPhone OS Note: Cookies are not shared among applications in iPhone OS.

So it seems like they should be "private" by default. You can also use the [NSHTTPCookieStorage sharedHTTPCookieStorage] object to set the cookie storage policy to not store cookies at all, or you could use the deleteCookie: method to clean up after yourself if you needed to.

As for other content that is loaded by your UIWebview, when you create the NSURLRequest that is loaded by your webview, you can set a cache policy that controls if the content will be cached. For example:

NSURLRequest * request = [NSURLRequest requestWithURL: [NSURL URLWithString: url]
                                          cachePolicy: NSURLRequestReloadIgnoringLocalAndRemoteCacheData
                                       timeoutInterval: 60.0]
[webView loadRequest: request];

NSURLRequestReloadIgnoringLocalAndRemoteCacheData tells the request to ignore the cache and load the request from the network. I'm not sure if it also prevents the response from the network from being cached, but to be sure, you could alway remove it from the cache yourself:

[NSURLCache sharedURLCache] removeCachedResponseForRequest:request];
like image 108
Jason Jenkins Avatar answered Feb 02 '23 01:02

Jason Jenkins