Xcode7.0.1:用Xcode7.0.1在ios9上请求http数据失败问题

升级Xcode7后,在ios9上运行程序(应用内的网络请求用的http),发现数据加载不出来,提示错误,数据加载失败,如下:

The resource could not be loaded because the App Transport Security policy requires the use of a secure connection

查资料,发现是ios9的新特性造成的。iOS9的一个新特性-ATS,全称为App Transport Security,旨在提高iOS设备与服务器交互的安全性。在ios9上,要求使用的网络请求为https。但是在短时间内无法将http改为https这种情况下,要想解决该问题,可以在info.plist文件中指明,将应用的https回退到http。

解决方案如下:

  1. 在Info.plist中添加NSAppTransportSecurity类型Dictionary

  2. NSAppTransportSecurity下添加NSAllowsArbitraryLoads类型Boolean,值设为YES

原文地址:https://www.cnblogs.com/guatiantian/p/4913592.html