NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9813) in iOS 9 with Xcode 7.1

北城以北 提交于 2019-11-29 02:55:57
Aakash Gupta

From iOS 9 Onwards Apple Enforce To make HTTP Request with Specific Host for Security Purpose. //Also works on iOS 10 with Swift 3

For that, you need to Add NSAppTransportSecurity Dictionary into your .plist the file of Project. Then your plist will look something like this as follows.

Tap to see .Plist File Image

Here NSAllowArbitraryLoads basically means Connect to anything (this is probably BAD). Instead of this you can add a particular Host to be Connect.

BoxAndBirdie

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:

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

Your info.plist file should look like this

See this post: https://stackoverflow.com/a/31077483/6763322

I just ran it in the device instead of simulator.It started working

For those who are working in xcode 8...this will help you...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!