iOS 8的基本身份验证失败

Sni*_*ips 5 iphone basic-authentication ios ios8

我有一个iOS应用程序与运行Rails的服务器交互,并且已经稳定可靠3年了.该服务器需要基本和SSL认证,并且在iOS 7中一直运行良好.

但是,我现在看到运行iOS 8的设备的身份验证问题.运行<iOS 8的设备/模拟器继续正常工作.

在应用程序初始化时,有一系列数据请求要与需要通过基本身份验证的服务器同步.

这会导致调用以下委托方法,

willSendRequestForAuthenticationChallenge
Run Code Online (Sandbox Code Playgroud)

......问题出现是因为这些问题无休止地受到挑战 - 当[challenge previousFailureCount]> 0时,代码故意在第二次尝试失败(代码路径遵循标准做法,如果previousFailureCount> 0则调用cancelAuthenticationChallenge) - 见下文.

我已经记录了挑战ID,即使在previousFailureCount> 0时,每个挑战都有所不同.

- (void)connection:(NSURLConnection *)connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
{

    if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodHTTPBasic])
    {   
        if ([challenge previousFailureCount] == 0)
        {
            NSURLCredential *newCredential;

            newCredential = [NSURLCredential credentialWithUser:MY_USERNAME
                            password:MY_PASSWORD
                            persistence:NSURLCredentialPersistenceForSession]; // Retain for rest of session

            [[challenge sender] useCredential:newCredential forAuthenticationChallenge:challenge];
        }
        else
        {
            [[challenge sender] cancelAuthenticationChallenge:challenge];

            // ...error will be handled by connection didFailWithError
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

如果我敲除了检查previousFailureCount的调用,那么挑战方法会有无休止的调用.

但是,一旦这一系列故障失败,后续和后来的"个人"NSUrlRequests将成功通过身份验证.

同样,这个问题特定于iOS 8.任何想法为什么"快速"连续的身份验证请求会在iOS 8中失败,但在iOS 7中工作?

谢谢.

Sni*_*ips 0

这个问题的答案/更新也解决了我所看到的问题。

iOS8 上 NSURLConnection 超时

同样,iOS 8 中发生了一些变化,需要进行此修复。