search

Home  >  Q&A  >  body text

objective-c - 带Cookie的WebView如何设置接收和删除?

- (void)getCookies:(NSURL *)url
{

    
    NSArray *cookjar = [[NSHTTPCookieStorage sharedHTTPCookieStorage]cookiesForURL:url];
    for (NSHTTPCookie *cookie in cookjar ) {
        DLog(@"cookie.version===%lu,cookie.name===%@,cookie.domain===%@,cookie.path===%@,cookie.isSessionOnly===%@",(unsigned long)cookie.version,cookie.name,cookie.domain,cookie.path,cookie.isSessionOnly?@"TRUE":@"FALSE");
    }
}


- (void)deleteCookies
{
    NSHTTPCookieStorage *cookieJar = [NSHTTPCookieStorage sharedHTTPCookieStorage];
    NSArray *_tmpArray = [NSArray arrayWithArray:[cookieJar cookies]];
    for (id obj in _tmpArray) {
        [cookieJar deleteCookie:obj];
         DLog(@"NSHTTPCookie===%@",cookieJar);
    }
}

高洛峰高洛峰2757 days ago398

reply all(0)I'll reply

No reply
  • Cancelreply