iOS9默认网络访问都是SSL

问题描述:今天输入法适配iOS9,发现所有网络都不能访问了

问题分析
1.做了一个Demo,发现可以访问网络,访问的是http://www.baidu.com
2.调试设置项,发现所有返回的错误为“Error Domain=NSURLErrorDomain Code=-1200 "发生了 SSL 错误,无法建立与该服务器的安全连接。"”
3.把访问链接复制到浏览器中访问,发现有返回数据
4.仔细研究了一下错误发现所有的访问链接都变成了https://
5.在demo中证实所有iOS9会自动以SSL的方式访问所有网络链接

问题解决
在info.plist中,加入:

<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>yourserver.com</key>
<dict>
<!--Include to allow subdomains-->
<key>NSIncludesSubdomains</key>
<true/>
<!--Include to allow HTTP requests-->
<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
<true/>
<!--Include to specify minimum TLS version-->
<key>NSTemporaryExceptionMinimumTLSVersion</key>
<string>TLSv1.1</string>
</dict>
</dict>
</dict>

或者你希望所有都打开TLS,可以这样写:

NSAppTransportSecurity

<!--Include to allow all connections (DANGER)-->
NSAllowsArbitraryLoads

 

PS:官方文档:https://developer.apple.com/library/prerelease/ios/technotes/App-Transport-Security-Technote/