"发生了SSL错误,无法与服务器建立安全连接."

Ulb*_*lbo 5 ssl https ios tls1.2 ios10

在iOS 10.2中,当我们尝试与几个不同的api进行通信时,我们会发现此错误.奇怪的是,我们有时只会在同一个网址的200个请求中有2个进行此操作.但另一方面,我有时可以做3000次api通话,但没有看到问题.

据我所知,这与ATS有关.输出还告诉我们,我们得到一个与ATS相关的错误代码:kCFStreamErrorCodeKey = -9806.

但是我不明白这与ATS有什么关系,因为有几点:

  • 我打电话的网址是https.
  • 服务器具有有效的TLSv1.2证书
  • 我试图创建一个例外,但似乎没有做任何事情

我们尝试以不同的方式创建异常,既允许任意加载,又为域创建异常.

即使在服务器具有有效证书时不需要,我们也尝试创建异常

这就是我们为域创建例外的方式.

<key>NSAppTransportSecurity</key>
    <dict>
      <key>NSExceptionDomains</key>
      <dict>
        <key>deezer.com</key>
        <dict>
          <key>NSIncludesSubdomains</key>
          <true/>
          <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
          <true/>
          <key>NSTemporaryExceptionMinimumTLSVersion</key>
          <string>TLSv1.2</string>
          <key>NSTemporaryExceptionRequiresForwardSecrecy</key>
          <false/>
        </dict>
      </dict>
    </dict>
Run Code Online (Sandbox Code Playgroud)

这就是我们启用仲裁负载的方式:

<key>NSAppTransportSecurity</key>
  <dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
  </dict>
Run Code Online (Sandbox Code Playgroud)

另一个奇怪的是我们只在iOS 10(10.2)中看到这个.当我们在iOS 9.3中进行测试时,一切都按预期工作.

我已经制作了一个示例应用程序来重现这一点.

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    [self Perform];
}

int i = 0;

- (void) Perform
{
    NSURLSessionConfiguration *defaultConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration];

    NSURLSession *sessionWithoutADelegate = [NSURLSession sessionWithConfiguration:defaultConfiguration];
    NSURL *url = [NSURL URLWithString:(@"https://api.deezer.com/chart/0/tracks")];

    [[sessionWithoutADelegate dataTaskWithURL:url completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
        if(error != NULL)
        {
            NSLog(@"Got response with error %@.\n", error);
        }

        NSLog(@"%d",i);
        i++;
        if(i <1000)
        {
            [self Perform];
        }


    }] resume];
}
Run Code Online (Sandbox Code Playgroud)

有没有人有解决方案的想法?谢谢