【问题标题】:Creating a non-tracking in-app web browser创建非跟踪应用内网络浏览器
【发布时间】:2021-07-15 14:45:36
【问题描述】:

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

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

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

单独清除 cookie
NSHTTPCookieStorage *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


【解决方案1】:

尝试为 WKWebViewConfiguration

WKWebsiteDataStore 设置 nonPersistentDataStore

这里是一个示例代码sn-p

let webVuConfiguration = WKWebViewConfiguration()
webVuConfiguration.websiteDataStore =WKWebsiteDataStore.nonPersistentDataStore()
let webView = WKWebView(frame: webviewRect, configuration: webVuConfiguration)

【讨论】:

    【解决方案2】:

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

    WKWebViewConfiguration * config = [WKWebViewConfiguration new];
    config.websiteDataStore = [WKWebsiteDataStore nonPersistentDataStore];   
    webView = [[WKWebView alloc]initWithFrame:viewFrame configuration:config];
    

    【讨论】:

    • 感谢您的夸奖 :) 很高兴能为您提供一些帮助,我不认为 Obj-C 开发人员是平民 :) 你知道老是金
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-12-25
    • 1970-01-01
    • 1970-01-01
    • 2013-08-28
    • 2016-03-18
    • 2012-10-30
    • 2012-01-03
    相关资源
    最近更新 更多