Private browsing with UIWebView on iPhone and iPad

How do existing applications implement this feature?

Is it possible to store cookies only for certain sites and only inside my application? I understand that web browsing stores cookies in a shared mode ... so they are shared by Safari and other applications that use UIWebView.

+4
source share
2 answers

According to NSHTTPCookieStorage docs cookies are not distributed between applications:

iPhone OS Note: cookies are not used among applications on the iPhone OS.

It looks like they should be "private" by default. You can also use the [NSHTTPCookieStorage sharedHTTPCookieStorage] object to set a cookie storage policy so as not to store cookies at all, or you can use the deleteCookie: method to clear after yourself if you need to.

As for the other content loaded by your UIWebview, when creating the NSURLRequest loaded by your webview, you can set a caching policy that will control whether the content will be cached. For instance:

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

NSURLRequestReloadIgnoringLocalAndRemoteCacheData indicates that the request ignores the cache and loads the request from the network. I'm not sure if this also prevents caching the response from the network, but of course you can always remove it from the cache:

 [NSURLCache sharedURLCache] removeCachedResponseForRequest:request]; 
+5
source

If you are talking about private browsing, UIWebView does not actually save the history after closing the application (only for temporarily moving back and forth). Instead, you have to implement the storage history yourself, so it will be automatically private browsing.

Short answer: do nothing. Its already in private browsing mode.

EDIT: to handle the cache check this method:

 - (NSCachedURLResponse *)connection:(NSURLConnection *)connection willCacheResponse:(NSCachedURLResponse *)cachedResponse 

And do cashedResponse return no.

+4
source

Source: https://habr.com/ru/post/1312745/


All Articles