iOS5: willSendRequestForAuthenticationChallenge method is running recursive

后端 未结 2 332
旧巷少年郎
旧巷少年郎 2021-01-19 05:09

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 hap

相关标签:
2条回答
  • 2021-01-19 05:59

    You need to check the error count and cancel the authentication challenge appropriately:

    if ([challenge previousFailureCount]) {
        [[challenge sender] cancelAuthenticationChallenge:challenge];
    } else {
        [[challenge sender] useCredential:credential forAuthenticationChallenge:challenge];
    }
    
    0 讨论(0)
  • 2021-01-19 06:01

    Try this.

    - (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]; 
            }
    
    }
    
    0 讨论(0)
提交回复
热议问题