Reputation: 91
Why is that NSURLConnection's didCancelAuthenticationChallenge delegate method is never called, even after manually cancelling the Auth challenge (which in fact gets cancelled as supposed) ?
I paste some bits of the relevant code below, keep in mind that all other delegate methods are called as supposed EXCEPT for - (void)connection:(NSURLConnection *)connection didCancelAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
Thanks for any help. //Diego
...
NSURLConnection *serviceConnection = [NSURLConnection connectionWithRequest:serviceRequest delegate:self];
...
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
if ([challenge previousFailureCount]) {
NSLog(@"Invalid credentials... Cancelling.");
[[challenge sender] cancelAuthenticationChallenge:challenge];
// AT THIS POINT cancelAuthenticationChallenge HAS BEEN CALLED, YET, DELEGATE METHOD IS NOT CALLED.
} else {
if ([ud stringForKey:@"username"] && [ud stringForKey:@"password"]) {
NSLog(@"Service is trying to login with locally stored user and password from NSUserDefaults");
NSURLCredential *credential = [NSURLCredential credentialWithUser:[ud stringForKey:@"username"]
password:[ud stringForKey:@"password"]
persistence:NSURLCredentialPersistenceForSession];
[[challenge sender]useCredential:credential forAuthenticationChallenge:challenge];
} else {
[delegate STServiceNeedsLoginInfo:self];
}
}
}
- (void)connection:(NSURLConnection *)connection didCancelAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
NSLog(@"Failed login with status code: %d", [(NSHTTPURLResponse*)[challenge failureResponse]statusCode]);
// THIS METHOD IS NEVER CALLED. WHY ?
}
Upvotes: 2
Views: 703
Reputation: 15003
I believe that delegate method is provided for if the connection cancels authentication, not you. e.g. if you took too long responding to a challenge, the connection could theoretically cancel auth.
Upvotes: 2