[iOS] NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9802)

這篇超容易踩到的,除了使用 http 會遇到,連使用https 也會遇到,如果沒去設定而且連到 https 的網站,會顯示這一個  Error:

Error Domain=NSURLErrorDomain Code=-1200 “An SSL error has occurred and a secure connection to the server cannot be made


If you try to make HTTP requests with ATS enabled (using NSURLSession or libraries like AFNetworking), you’ll see errors like this.

Here’s how to disable ATS entirely. Open Info.plist, and add the following lines:


You have to add just the NSAllowsArbitraryLoads key to YES in NSAppTransportSecurity dictionary in your info.plist file.