7

我正在尝试创建一个不会在本地跟踪或存储任何浏览历史记录的 web 视图(作为练习)。
我已经做到了,当 webview 关闭时,它会调用以下内容

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

但我发现像谷歌搜索历史这样的东西在会话之间仍然存在一些。我也尝试过分别清除cookies

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

仍然无济于事。当创建新的网络视图时,Google 搜索仍会显示。
有没有人知道删除谷歌用来匹配搜索历史的标识符的方法?我担心它类似于捆绑标识符,防止被读取可能有点棘手。
任何想法表示赞赏。
问候,
卢克

4

2 回答 2

11

尝试为WKWebViewConfigurationWKWebsiteDataStore设置nonPersistentDataStore

这是一个示例代码片段

let webVuConfiguration = WKWebViewConfiguration()
webVuConfiguration.websiteDataStore =WKWebsiteDataStore.nonPersistentDataStore()
let webView = WKWebView(frame: webviewRect, configuration: webVuConfiguration)
于 2017-03-30T19:55:25.553 回答
3

为了恭维 Durai Amuthan.H 的回答,这是我们仍然喜欢使用 Obj-C 的平民的答案

WKWebViewConfiguration * config = [WKWebViewConfiguration new];
config.websiteDataStore = [WKWebsiteDataStore nonPersistentDataStore];   
webView = [[WKWebView alloc]initWithFrame:viewFrame configuration:config];
于 2017-03-30T20:05:11.513 回答