2
なぜAuthチャレンジを手動でキャンセルした後でも、NSURLConnectionのdidCancelAuthenticationChallengeデリゲートメソッドが呼び出されないのはなぜですか?NSURLConnectionのdidCancelAuthenticationChallengeデリゲートメソッドが呼び出されなかった
私は任意のヘルプ- (void)connection:(NSURLConnection *)connection didCancelAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
感謝を除くなって他のすべてのデリゲートメソッドが呼び出されることに注意して、以下の関連するコードの一部のビットを貼り付けます。 //ディエゴ・
...
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 ?
}
はいMike、あなたに同意している人もいれば、私のように、バグだと思う人もいます。ドキュメントは何度も矛盾するので、Appleにバグレポートを投稿してみましょう。ありがとう! – DiegoMax