Two questions:

  1. When is the URLSession:didReceiveChallenge:completionHandler: delegate to NSURLSessionDelegate ? If the answer to the request did not come with a 2XX status code?

  2. Will I be able to use this delegate method for authorization, if for the repeated request I need to update the authorization token @ "ticket" in the request body?

     NSURLSession *session = [NSURLSession sharedSession]; NSError *error; NSDictionary *mapData = @{ @"userIdentity": @{ @"ticket": [SecretStorage sharedInstance].ticket, @"hotelId": [SecretStorage sharedInstance].hotelId, @"language": @"ru" } }; NSData *postData = [NSJSONSerialization dataWithJSONObject:mapData options:0 error:&error]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"example.com"] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.f]; [request addValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; [request setHTTPMethod:@"POST"]; [request setHTTPBody:postData]; NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) { NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil]; NSLog(@"%@", json); }]; [dataTask resume]; 

    0