iOS5:willSendRequestForAuthenticationChallenge方法正在运行递归 [英] iOS5: willSendRequestForAuthenticationChallenge method is running recursive
本文介绍了iOS5:willSendRequestForAuthenticationChallenge方法正在运行递归的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用以下代码对远程服务器的用户进行身份验证。如果我提供了正确的用户名和密码,则没有问题,因为身份验证正在发生,我从服务器获得响应。
I am using the below code for authentication of the user with the remote server.If I am giving correct username and password, there is no issue because authentication is happening and I am getting the response from server.
但是当我提供错误的凭据时,会以递归方式调用此方法,因此我无法解决此问题。
But when I am giving wrong credentials,this method is called in recursive manner, so I am not able to break this.
请帮助我,如何打破这一点,以便我能够显示身份验证失败的警报消息。
Please help me, how to break this so that I should be able to show the authentication failed alert message.
- (void)connection:(NSURLConnection *)connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
{
NSURLCredential *credential = [NSURLCredential credentialWithUser:@"username"
password:@"password"
persistence:NSURLCredentialPersistenceForSession];
[[challenge sender] useCredential:credential forAuthenticationChallenge:challenge];
}
推荐答案
试试这个。
- (void)connection:(NSURLConnection *)connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
{
if ([challenge previousFailureCount] > 0) {
// do something may be alert message
}
else
{
NSURLCredential *credential = [NSURLCredential credentialWithUser:@"username"
password:@"password"
persistence:NSURLCredentialPersistenceForSession];
[[challenge sender] useCredential:credential forAuthenticationChallenge:challenge];
}
}
这篇关于iOS5:willSendRequestForAuthenticationChallenge方法正在运行递归的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文