我正在尝试通过网络服务器对用户进行身份验证,并在我的登录视图按钮中调用以下方法来执行此操作。
- (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];
}
}
成功验证后是否有任何状态返回,以便我可以使用该状态并传递给下一个视图,否则显示错误。
答案 0 :(得分:1)
Jsut Call connectionDidFinishLoading:Method。
答案 1 :(得分:0)
好的,正如我的评论所说:
实际上,connectionDidFinishLoading:方法告诉您可以继续下一步。