如何在不共享Cookie的情况下拥有多个Webkit实例? [英] How can I have multiple instances of webkit without sharing cookies?

查看:91
本文介绍了如何在不共享Cookie的情况下拥有多个Webkit实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,可以创建几个WebView实例,并且希望它们尽可能独立地运行.

I have an app that creates a couple of WebView instances and I'd like to have them operate as independently as possible.

至少,我不希望他们共享Cookie.谷歌快速搜索给了我喜欢你做不到"的结果.我希望有人能提供更好的答案.

At the very least, I don't want them sharing cookies. A quick google search gave me results liking "you can't." I'm hoping someone has a better answer.

推荐答案

基本答案是你不能".

看了一点之后,我认为这是可能的,但是极其复杂.这将涉及在WebView上实现resourceLoadDelegate,该实现实现-webView:resource:willSendRequest:redirectResponse:fromDataSource:并修改请求以关闭HTTPShouldHandleCookies并手动将任何相关的cookie添加到请求中.它还必须实现-webView:resource:didReceiveResponse:fromDataSource:来查找有关从服务器返回的任何cookie的信息.您可以为每个网络视图分配/初始化自己的NSHTTPCookieStorage副本,并使用该副本存储/检索cookie.

After looking at this for a bit, I think it's possible, but extremely complicated. It would involve implementing a resourceLoadDelegate on your WebView that implements -webView:resource:willSendRequest:redirectResponse:fromDataSource: and modifies the request to turn off HTTPShouldHandleCookies and adds any relevant cookies to the request manually. It also has to implement -webView:resource:didReceiveResponse:fromDataSource: to find out about any cookies returned from the server. You can alloc/init your own copy of NSHTTPCookieStorage per-webview and use that to store/retrieve the cookies.

这篇关于如何在不共享Cookie的情况下拥有多个Webkit实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆