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
iOS xcode 7网络请求错误failure Error Domain=NSURLErrorDomain Code=-1022 "The resource could not be loaded_第1张图片
再次运行,即可成功运行~~~!!!

你可能感兴趣的:(ios,xcode,网络请求失败)