Почему метод делегата NSURLConnection didCancelAuthenticationChallenge никогда не вызывается, даже после ручной отмены вызова Auth (который фактически отменяется, как предполагается)?
Я вставляю некоторые биты соответствующего кода ниже, имейте в виду, что все другие методы делегата вызываются как ИСКЛЮЧЕННЫЕ для - (void)connection:(NSURLConnection *)connection didCancelAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
Спасибо за любую помощь.
// 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 ?
}