【发布时间】:2021-07-15 14:45:36
【问题描述】:
我正在尝试创建一个不会在本地跟踪或存储任何浏览历史记录的 web 视图(作为练习)。
我已经做到了,当 webview 关闭时,它会调用以下内容
[[NSURLSession sharedSession]resetWithCompletionHandler:^{}];
但我发现像谷歌搜索历史这样的东西在会话之间仍然存在一些。我也试过通过
单独清除 cookieNSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
for (NSHTTPCookie *cookie in [storage cookies]) {
[storage deleteCookie:cookie];
}
[[NSUserDefaults standardUserDefaults] synchronize];
仍然无济于事。创建新的网络视图时,Google 搜索仍会显示。
有没有人知道删除谷歌用来匹配搜索历史的标识符的方法?我担心它类似于捆绑标识符,防止被读取可能有点棘手。
任何想法表示赞赏。
问候,
卢克
【问题讨论】:
-
您是否也尝试过清理缓存? [[NSURLCache sharedURLCache] removeAllCachedResponses];
-
我假设是这样。
- (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. */。反正我也会试试的。 -
设置Wkwebview配置网站DataStore为WKWebsiteDataStore.nonPersistentDataStore(),看看是否有效
-
Incase of NSURLConnection ... in case of NSURLConnection ... in the delegate return nil for cachedResponse 在下面的委托方法
-(NSCachedURLResponse *)connection:(NSURLConnection *)connection willCacheResponse:(NSCachedURLResponse *)cachedResponse -
或者尝试删除缓存
[NSURLCache sharedURLCache] removeCachedResponseForRequest:request];
标签: ios nsurlsession nshttpcookie