cookie 保存登录状态
//设置 cookie
NSData * data = ({
NSArray * cookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:[NSURL URLWithString:@"http://codog.com.cn:8080/api/user/login"]];
[NSKeyedArchiver archivedDataWithRootObject:cookies];
});
[[NSUserDefaults standardUserDefaults] setObject:data forKey:Cookie_Name];
//验证 cookie
NSData * cookiesData = [[NSUserDefaults standardUserDefaults] objectForKey:Cookie_Name];
if ([cookiesData length]) {
NSArray * cookies = [NSKeyedUnarchiver unarchiveObjectWithData:cookiesData];
for (NSHTTPCookie * cookie in cookies) {
[[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookie:cookie];
}
}