7

I am trying to create a webview (as an exercise) that does not track or store any browsing history locally.
I have made it so that when the webview is closed, it calls the following

[[NSURLSession sharedSession]resetWithCompletionHandler:^{}];

but I am finding that things like google search history persists some how between sessions. I have also tried clearing cookies separately through

NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
    for (NSHTTPCookie *cookie in [storage cookies]) {
       [storage deleteCookie:cookie];
    }
[[NSUserDefaults standardUserDefaults] synchronize];

still to no avail. Google searches still show when a new web view is created.
Is anyone aware of a way to remove the identifier that google is using to match that search history back to me? I'm concerned it's something like the bundle identifier, which is probably a bit trickier to prevent being read.
Any ideas are appreciated.
Regards,
Luke

mylogon
  • 2,283
  • 2
  • 24
  • 39
  • did you try cleaning the cache also ? [[NSURLCache sharedURLCache] removeAllCachedResponses]; – Durai Amuthan.H Mar 30 '17 at 19:32
  • I'm assuming so. `- (void)resetWithCompletionHandler:(void (^)(void))completionHandler; /* empty all cookies, cache and credential stores, removes disk files, issues -flushWithCompletionHandler:. Invokes completionHandler() on the delegate queue if not nil. */`. I will try that also anyway. – mylogon Mar 30 '17 at 19:34
  • 1
    Set the Wkwebviewconfiguration websiteDataStore as WKWebsiteDataStore.nonPersistentDataStore() and see if it works – Durai Amuthan.H Mar 30 '17 at 19:38
  • Incase of NSURLConnection ... in the delegate return nil for cachedResponse in the following delegate method `-(NSCachedURLResponse *)connection:(NSURLConnection *)connection willCacheResponse:(NSCachedURLResponse *)cachedResponse` – Durai Amuthan.H Mar 30 '17 at 19:44
  • Or else try removing the cache `[NSURLCache sharedURLCache] removeCachedResponseForRequest:request];` – Durai Amuthan.H Mar 30 '17 at 19:49
  • As far as website request is concerned try to use `NSURLRequestReloadIgnoringLocalAndRemoteCacheData` for `NSURLRequest` – Durai Amuthan.H Mar 30 '17 at 19:50
  • Right on the money with the nonPersistentDataStore. If you give that as an answer, the bounty is yours mate – mylogon Mar 30 '17 at 19:50

2 Answers2

11

Try setting nonPersistentDataStore for WKWebsiteDataStore of WKWebViewConfiguration

Here is a sample code snippet

let webVuConfiguration = WKWebViewConfiguration()
webVuConfiguration.websiteDataStore =WKWebsiteDataStore.nonPersistentDataStore()
let webView = WKWebView(frame: webviewRect, configuration: webVuConfiguration)
Durai Amuthan.H
  • 28,889
  • 6
  • 148
  • 223
3

To compliment Durai Amuthan.H's answer, here is the answer for us plebs who still like to use Obj-C

WKWebViewConfiguration * config = [WKWebViewConfiguration new];
config.websiteDataStore = [WKWebsiteDataStore nonPersistentDataStore];   
webView = [[WKWebView alloc]initWithFrame:viewFrame configuration:config];
mylogon
  • 2,283
  • 2
  • 24
  • 39
  • 1
    Thanks for the compliment :) I am glad that I am of some help to you and I don't think Obj-C developers are plebs :) you know old is gold – Durai Amuthan.H Mar 30 '17 at 20:18