xCode 9 - iOS 11: NSURLConnection - sendAsynchronousRequest fails

dor506 picture dor506 · Jun 22, 2017 · Viewed 40.7k times · Source

I just downloaded the latest version of xCode (9.0 beta (9M136h)).

However, when I try to make a request to my server in iOS 11 simulator (Using NSURLConnection sendAsynchronousRequest), an error is received:

NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9807) NSURLConnection finished with error - code -1202

NSError object contains the message - @"NSLocalizedDescription" : @"The certificate for this server is invalid. You might be connecting to a server that is pretending to be “***” which could put your confidential information at risk."

The plist contains:

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

so it is not the problem in this case (I guess)

Needless to say that it is working in iOS 10/9/8

Any suggestions?

Thanks in advance!

Answer

Carter4502 picture Carter4502 · Oct 26, 2017

You need to allow your application to run HTTP (no S) connections. By default, Apple only allows HTTPS:

  1. go to your info.plist

    here

  2. then press the plus icon on any of them

  3. Search for "App Transport Security Settings" here

  4. click the little arrow to the left and find "Allow arbitrary loads", by default it is set to "NO" change it to "YES"