Xcode7 网络请求报错:The resource could not be loaded because the App Transport Security policy requires th

这些天打开公司的应用,总是网络请求报错。之前没有细看报错信息,还以为是后台把服务停了呢。后来询问安卓的同事,他们的数据没问题。这才仔细的看了下报错信息:

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=0x7fbbb9dd4dc0 {Error Domain=kCFErrorDomainCFNetwork Code=-1022 "The resource could not be loaded because the App Transport Security policy requires the use of a secure connection." UserInfo={NSErrorFailingURLStringKey=http://app.dajike.com/Jbbs/call, NSLocalizedDescription=The resource could not be loaded because the App Transport Security policy requires the use of a secure connection., NSErrorFailingURLKey=http://app.dajike.com/Jbbs/call}}, NSErrorFailingURLStringKey=http://app.dajike.com/Jbbs/call, NSErrorFailingURLKey=http://app.dajike.com/Jbbs/call, NSLocalizedDescription=The resource could not be loaded because the App Transport Security policy requires the use of a secure connection.}


这是由于iOS9添加了新特性:App Transport Security (ATS),最近刚刚升级了xcode到版本七;

解决办法:

  1. 在Info.plist中添加NSAppTransportSecurity类型Dictionary
  2. NSAppTransportSecurity下添加NSAllowsArbitraryLoads类型Boolean,值设为YES

你可能感兴趣的:(iOS)