iOS xcode 7网络请求错误failure Error Domain=NSURLErrorDomain Code=-1022 "The resource could not be loaded

在我们使用(xocde7.0)打开以前的项目时,发现之前的项目在原来的版本上都没有问题,在xcode7.0上网络请求部分发生了错误,会看到有这么一段东西输出在控制台(据说7.1没那问题);

2015-11-20 16:12:16.569 AFNetworking_(3.0)[3091:1743943] App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app’s Info.plist file. 
2015-11-20 16:12:16.662 AFNetworking_(3.0)[3091:1742917] failure Error Domain=NSURLErrorDomain Code=-1022 “The resource could not be loaded because the App Transport Security policy requires the use of a secure connection.” UserInfo={NSUnderlyingError=0x7fedb8e02ef0 {Error Domain=kCFErrorDomainCFNetwork Code=-1022 “(null)”}, NSErrorFailingURLStringKey=http://comment.api.163.com/api/json/post/list/new/hot/ent2_bbs/AI1O4EEK00032DGD/0/10/10/2/2, NSErrorFailingURLKey=http://comment.api.163.com/api/json/post/list/new/hot/ent2_bbs/AI1O4EEK00032DGD/0/10/10/2/2, NSLocalizedDescription=The resource could not be loaded because the App Transport Security policy requires the use of a secure connection.}

那是因为OS9让所有的HTTP默认使用了HTTPS,原来的HTTP协议传输都改成TLS1.2协议进行传输。直接造成的情况就是App发请求的时候弹出网络无法连接。解决方法,在工程里面的Info.plist里面添加如下节点: 
还有种新式该法 
App Transport Security Settings Dictionary 
Allow Arbitrary Loads Boolean Yes 
这里写图片描述

再次运行,即可成功运行~~~!!!

-------------------------------------------

新式写法:


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值