How to delete all cookies of UIWebView?

Vaibhav Saran picture Vaibhav Saran · Dec 17, 2010 · Viewed 46.3k times · Source

In my application, I have a UIWebview that loads linkedin auth page for login. When user logs in, cookies saves into the application.

My app has a logout button that is not related to linkedin login. So when user clicks on this button, he logs off from the app. I want that this log off will clear his linkedin cookies also from the app, so that user will log out completely.

Answer

Sergio Moura picture Sergio Moura · Dec 17, 2010

According to this question, you can go through each cookie in the "Cookie Jar" and delete them, like so:

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