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.
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];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With