在iOS开发中,我们经常会用到AFNetworking类调用远程数据,如果远程数据采用HTTP协议的话,会报出"The resource could not be loaded because the App Transport Security policy requires the use of a secure connection"这样的错误提示
原因是在iOS9之后,苹果把原HTTP协议改成了HTTPS协议,默认不可直接在HTTP协议下使用GET和POST,但可在info.plist中配置启用HTTP协议,配置方法如下:
1. 在XCode中选中info.plist,在右边的配置列表中点击Information Property List右边的加号,添加节点App Transport Security Settings
2. 并在App Transport Security Settings下面添加子节点Allow Arbitrary Loads
3. 设置Allow Arbitrary Loads的值为YES
搞定OK!