I'm making an async url request with the new iOS 5 method: sendAsynchronousRequest:queue:completionHandler:. This uses a block to handle the response, but no NSURLConnectionDelegate delegate methods are being called? I can't see a way to set the delegate for the NSUrlConnection class in this instance?
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
NSLog(@"HTTP response code: %i", httpResponse.statusCode);
if (error != nil) {
NSLog(@"There was error with the synchronous request: %@", error.description);
}
}];
The reason I need the delegate methods is because one of my calls gets a 401 response, which iOS handles in a different way - deferring authentication to delegate methods. When a 401 response comes back - httpResponse.statusCode is just "0".
Is there a way to stop iOS from trying to handle a 401 differently? In particular, I'm thinking I need to use the continueWithoutCredentialForAuthenticationChallenge: delegate method - but no delegates are being called in this case.
Thanks!
You need to use a NSURLConnection instance and use a delegate for that. The sendAsynchronousRequest:queue:completionHandler:
is a shortcut for the same but with the default behavior without a delegate.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With