Cookies in UIWebView

China☆狼群 提交于 2019-11-30 13:05:48
samsam

I had to deal with the exact same issue and I found 2 ways to deal with that problem. I first noticed that cookies get (sometimes) set at weird times (Strange behaviour especially with ios 4.0).

  • Instant deletion of cookies after the user was on a webview often didn't get me the expected results.

I then integrated a persistant, manual flag that was set True on a "logout" (aka clear all cookies / delete other user data) action. upon the next login (aka user-login-based action) I cleared the cookies again (the same way you did it in your code-post).

Later I found out, that listening to NSHTTPCookieManagerCookiesChangedNotification and then deleting cookies worked really well too.

hope I could help.

Try changing the cookie acceptance policy instead:

[NSHTTPCookieStorage setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyNever];

Use following and it will work..

   NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
   NSHTTPCookie *cookie;
   for(cookie in [storage cookies])
    {
      NSLog(@"cookie to be deleted:%@", cookie);
      [storage deleteCookie:cookie];
    }
   [[NSUserDefaults standardUserDefaults] synchronize];

here don't miss last line [[NSUserDefaults standardUserDefaults] synchronize]; otherwise you will remain puzzle.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!