我试图通过Web服务器对用户进行身份验证,然后在我的登录视图按钮touch中调用以下方法来进行身份验证。
- (void)connection:(NSURLConnection *)connection
didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
{
NSLog(@"challenge failure %d", [challenge previousFailureCount]);
// Access has failed two times...
if ([challenge previousFailureCount] == 0)
{
//NSLog(@"desc %@",[connection description]);
NSURLCredential *cred = [[[NSURLCredential alloc] initWithUser:userName.text password:passWord.text
persistence:NSURLCredentialPersistenceForSession] autorelease];
[[challenge sender] useCredential:cred forAuthenticationChallenge:challenge];
// need to call new view on correct authentication
[connection release];
}
else {// Answer the challenge
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Authentication error"
message:@"Invalid Credentials" delegate:self
cancelButtonTitle:@"Retry"
otherButtonTitles:nil];
[alert show];
[alert release];
}
}
成功验证后是否返回任何状态,以便我可以使用该状态并传递到下一个视图,否则显示错误。
最佳答案
好的,正如我的评论中所述:
实际上,connectionDidFinishLoading:方法告诉您可以继续进行下一步。