Disabling or deleting cookies in WebView without affecting other applications
I'm working on a problem in my Mac OSX 10.5 application that requires deleting cookies on user开发者_开发技巧 sign-off from the application - so that a different user can sign-in without the need to quit the application. When user authenticates for the first time, the WebView receives and caches 5 cookies using the singleton cookie storage class NSHTTPCookieStorage. When I try to retrieve the cookies using [NSHTTPCookieStorage cookiesForURL:] method, I get only 4. Which means that the 5th one is associated with some other URL. I cannot use the domain to identify the cookies because I may land up deleting cookies being used by other applications. I am thinking along the following lines:
- Disable cookies for the WebView when loading the URL.
- I have tried using [NSMutableURLRequest setHTTPShouldHandleCookies:NO] but that didn't help. And I cannot change the cookie policy using NSHTTPCookieStorage because it will affect other applications.
- Retrieve the cookies for the URL that I am loading
- I don't know if this is possible. I searched all the delegate methods available for WebView but didn't find anything
- Do a fresh reload of the URL using [WebFrame reloadFromOrigin] instance method
- this is only available for Mac OSX >= 10.6
- Recreate the instance of WebView
- didn't help, cookies still persist
I have also tried different options provided by WebPreferences class, but that didn't help. Thanks in advance for any hints to fix this issue.
Do you want to share cookies with Safari? If not (and I assume you don't), then look at IGIsolatedCookieWebView for an example of how to create your own private cookie store in webkit.
If you want to share cookies with Safari, you'll need to keep track of and then delete the relevant cookies at the appropriate time using NSHTTPCookieStorage
.
精彩评论