iOS 清理某一个cookies 或者全部 cookies

原贴地址:http://blog.csdn.net/jinglijun/article/details/9048959


清除所有的cookie 方法:

[html] view plaincopy
  1. NSURL *url = [NSURL URLWithString:@"http://www.baidu.com"];  
  2.     if (url) {  
  3.         NSArray *cookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:url];  
  4.         for (int i = 0; i < [cookies count]; i++) {  
  5.             NSHTTPCookie *cookie = (NSHTTPCookie *)[cookies objectAtIndex:i];  
  6.             [[NSHTTPCookieStorage sharedHTTPCookieStorage] deleteCookie:cookie];  
  7.               
  8.         }  

  清除某一个特定的cookie方法:

[html] view plaincopy
  1. NSArray * cookArray = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:[NSURL URLWithString:self.loadURL]]; NSString * successCode = @""; for (NSHTTPCookie*cookie in cookArray) { if ([cookie.name isEqualToString:@"cookiename"]) { [[NSHTTPCookieStorage sharedHTTPCookieStorage] deleteCookie:cookie]; } }  

清除某一个url缓存的方法:

[html] view plaincopy
  1. [[NSURLCache sharedURLCache] removeCachedResponseForRequest:[NSURLRequest requestWithURL:url]];  


清除所有缓存方法:        

[html] view plaincopy
  1. [[NSURLCache sharedURLCache] removeAllCachedResponses];  

展开阅读全文

没有更多推荐了,返回首页