You can probably get away with just using the sharedHTTPCookieStorage
for NSHTTPCookieStorage
, and then use setCookies:forURL:mainDocumentURL:
or the single setCookie:
- the latter might be better for your needs.
If this doesn't work you might need to setup the NSURLSessionConfiguration
and set the NSHTTPCookieStorage
The docs don't state it, but the defaultSessionConfiguration
might use the shared store anyway.
NSURLSession *session = [NSURLSession sharedSession];
[[session dataTaskWithURL:url completionHandler:^(NSData *data, NSURLResponse *response, NSError *error)
{
NSHTTPURLResponse *httpResp = (NSHTTPURLResponse*) response;
NSArray *cookies = [NSHTTPCookie cookiesWithResponseHeaderFields:[response allHeaderFields] forURL:[response URL]];
[[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookies:cookies forURL:[response URL] mainDocumentURL:nil];
NSLog(@"sttaus code %i", httpResp.statusCode);
if (error) {
[self.delegate signinWithError:error];
}
else {
[self.delegate signinWithJson:data];
}
}] resume];