How to delete all UIWebView cookies?

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

My application has a logout button that is not associated with the login name. Therefore, when the user clicks on this button, he exits the application. I want this logout to clear its associated cookies from the application as well, so that the user logs out completely.

+91
ios objective-c iphone uiwebview uiwebviewdelegate
Dec 17 '10 at 14:52
source share
4 answers

According to this question , you can go through each cookie in the β€œCookie Jar” and delete them, for example:

 NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage]; for (NSHTTPCookie *cookie in [storage cookies]) { [storage deleteCookie:cookie]; } [[NSUserDefaults standardUserDefaults] synchronize]; 
+209
Dec 17 '10 at 15:03
source share

Just wanted to add information about this.

On OS X 10.9 / iOS 7 , and then you can use -resetWithCompletionHandler: to clear cookies and cache, etc. the entire application from your sharedSession :

Empties all cookies, caches and credentials, deletes files on disk, downloads downloaded files downloaded to disk, and ensures that future requests appear on a new socket.

 [[NSURLSession sharedSession] resetWithCompletionHandler:^{ // Do something once it done. }]; 

For-In line with deleteCookie: sounds like a change when listing a collection to me. (I don’t know, maybe a bad idea?)

+8
Apr 05 '16 at 11:06
source share

You can make a function inside the html WebView that will clear the cookies.

If you need to perform the cleaning only after you can run this function with the Titanium event, only when the application starts.

+1
Apr 21 '12 at 11:48
source share

If someone is looking for a Swift Solution:

  let storage = HTTPCookieStorage.shared if let cookies = storage.cookies{ for cookie in cookies { storage.deleteCookie(cookie) } } 
0
Jun 27 '19 at 8:30
source share



All Articles