0

Use NSURLSession call api on https server not worked on ios9, worked on ios8

 NSURLRequest *urlRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:@"https://www.example.com/api"]];

    NSURLSession *urlSession = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];

    NSURLSessionDataTask *sessionTask = [urlSession dataTaskWithRequest:urlRequest
                                                      completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
                                                          if (error) {
                                                              NSLog(@"----: %@", error);
                                                          } else {
                                                              NSLog(@"-------: %@", [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]);
                                                          }
                                                      }];

When run on simulator or device, on device before iOS9, i'll get right response. But when run on iOS9+, will get

CFNetwork SSLHandshake failed (-9824)
NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9824)
Error Domain=NSURLErrorDomain Code=-1200 "An SSL error has occurred and a secure connection to the server cannot be made." UserInfo={_kCFStreamErrorCodeKey=-9824, NSLocalizedRecoverySuggestion=Would you like to connect to the server anyway?, NSUnderlyingError=0x7fda12f29830 {Error Domain=kCFErrorDomainCFNetwork Code=-1200 "(null)" UserInfo={_kCFStreamPropertySSLClientCertificateState=0, _kCFNetworkCFStreamSSLErrorOriginalValue=-9824, _kCFStreamErrorDomainKey=3, _kCFStreamErrorCodeKey=-9824}}, NSLocalizedDescription=An SSL error has occurred and a secure connection to the server cannot be made., NSErrorFailingURLKey=https://www.example.com/api, _kCFStreamErrorDomainKey=3}

I have tried some methods

  1. Disable ATS in plist file

    <key>NSAppTransportSecurity</key> <dict> <key>NSAllowsArbitraryLoads</key> <true/> </dict>

    1. Add NSExceptionDomains
    2. use command nscurl --ats-diagnostics https://www.example.com to test server connection, All configuration return FAIL

Any suggestion? Thanks

Arets Paeglis
  • 3,856
  • 4
  • 35
  • 44
Damon Wong
  • 61
  • 4
  • Can you try following link http://stackoverflow.com/questions/32755674/ios9-getting-error-an-ssl-error-has-occurred-and-a-secure-connection-to-the-ser – Peer Mohamed Thabib Aug 02 '16 at 12:17
  • Thanks, Peer. I've tried this solution, but nothing happened. I'm checking server configurations. – Damon Wong Aug 03 '16 at 02:18
  • I've resolved it. There are wrong configurations on server. Nginx configures ssl_protocol with TLSv.12 TLSv1.1 TLSv1, but openssl version 0.96 is not support TLSv1.2. upgrade openssl version 1.0.1 to enable this feature. – Damon Wong Aug 03 '16 at 05:41

0 Answers0