关闭

AFNetworking 传cookie

标签: IOS cookieAFNetworking
153人阅读 评论(0) 收藏 举报
分类:

- (void)saveCookies{

    NSData *cookiesData = [NSKeyedArchiver archivedDataWithRootObject: [[NSHTTPCookieStoragesharedHTTPCookieStorage] cookies]];

    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

    [defaults setObject: cookiesData forKey@"sessionCookies"];

    [defaults synchronize];

    

}

- (void)loadCookies{

    NSArray *cookies = [NSKeyedUnarchiver unarchiveObjectWithData: [[NSUserDefaultsstandardUserDefaults] objectForKey: @"sessionCookies"]];

    NSHTTPCookieStorage *cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];

    

    for (NSHTTPCookie *cookie in cookies){

        [cookieStorage setCookie: cookie];

    }

}

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场