iOS 中删除cookie的正确做法
2017-06-18 20:12 tlnshuju 阅读(1168) 评论(0) 编辑 收藏 举报需求:删除 qq 登录的 cookie,保证下次打开 qq 登录页面不会默认登录
实现:
NSString *url =@"https://w.mail.qq.com/cgi-bin/loginpage?
f=xhtml&kvclick=loginpage|app_push|enter|ios&ad=false&f=xhtml";//qq登录的 url
NSString *urlString =[url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSArray * cookArray = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:[NSURL URLWithString:urlString]];
for (NSHTTPCookie *cookie in cookArray)
{
if ([cookie.domain containsString:@"qq.com"])
{
[[NSHTTPCookieStorage sharedHTTPCookieStorage] deleteCookie:cookie];
}
}