iOS里cookie的使用

作者: 齐滇大圣 | 来源:发表于2015-11-04 20:18 被阅读326次
    设置cookie#####
        NSMutableDictionary *cookieProperties = [NSMutableDictionary dictionary];
        
        //从后台得到一些需要设置的cookie信息
        NSArray *cookies = [[User Instance] getCookies];
        for (NSDictionary *_cookieDic in cookies) {
            [cookieProperties setObject:[_cookieDic objectForKey:@"name"] forKey:NSHTTPCookieName];
            [cookieProperties setObject:[_cookieDic objectForKey:@"value"] forKey:NSHTTPCookieValue];
            [cookieProperties setObject:[_cookieDic objectForKey:@"domain"] forKey:NSHTTPCookieDomain];
            [cookieProperties setObject:[_cookieDic objectForKey:@"domain"] forKey:NSHTTPCookieOriginURL];
            [cookieProperties setObject:[_cookieDic objectForKey:@"path"] forKey:NSHTTPCookiePath];
            [cookieProperties setObject:[_cookieDic objectForKey:@"version"] forKey:NSHTTPCookieVersion];
            [cookieProperties setObject:[_cookieDic objectForKey:@"comment"] forKey:NSHTTPCookieComment];
        }
        
        NSHTTPCookie *cookie = [NSHTTPCookie cookieWithProperties:cookieProperties];
        [[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookie:cookie];
    
    删除cookie#####
     NSArray *cookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies];
     for (NSHTTPCookie *cookie in cookies){
        [[NSHTTPCookieStorage sharedHTTPCookieStorage] deleteCookie:cookie];
    }

    相关文章

      网友评论

        本文标题:iOS里cookie的使用

        本文链接:https://www.haomeiwen.com/subject/yszqhttx.html