iOS 中刪除cookie的正確做法
阿新 • • 發佈:2017-06-18
nbsp -h ring html tpc bold normal dom http
需求:刪除 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];
}
}
iOS 中刪除cookie的正確做法