0

Possible Duplicate:
How to delete all cookies of UIWebView?

Here i loading the content in html format and i need to delete all cookies and data in uiwebview, currently i have implemented these lines of code to delete the cookies but its some times working and not,why i do no...is there any error in my code

NSHTTPCookie *cookie;
    NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
    for (cookie in [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies]) {
        NSLog(@"%@", cookie);
        [storage deleteCookie:cookie];
    }
Community
  • 1
  • 1
dineshprasanna
  • 1,284
  • 4
  • 20
  • 37
  • It seems coockies are stored in NSUserDefaults. Look at comments to accepted answer at http://stackoverflow.com/questions/7567129/delete-cookies-uiwebview – Rok Jarc May 22 '12 at 13:10
  • thanks for your ans,but i have saved several datas in Nsuserdefaults when i implemented this code: NSString *appDomain = [[NSBundle mainBundle] bundleIdentifier]; [[NSUserDefaults standardUserDefaults] removePersistentDomainForName:appDomain]; its deletes all userdefaults – dineshprasanna May 22 '12 at 13:12
  • Yes, that is a big problem. One way would be to delete cookies when your application starts. It seems (didn't check this) this is a problem for iOS > 4.0. See also http://stackoverflow.com/questions/4471629/how-to-delete-all-cookies-of-uiwebview Your code seems correct. – Rok Jarc May 22 '12 at 13:16
  • 1
    Don't accept them in the first place: [NSHTTPCookieStorage setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyNever]; – PRNDL Development Studios May 22 '12 at 13:30

0 Answers0