iOS9 无法访问网络的解决方法

前两天升级了Xcode7.0,发现用模拟器运行某些需要网络访问的项目的时候会报错,具体如下:

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

技术分享

 

 

 

原因如下:

Xcode7.0要求App内访问的网络必须使用https协议,而当前使用的是 http协议。

 

后来从网上找到的解决方法是这样的:

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

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

 

具体实现方法如下:

  1.项目目录中找到Info.plist文件并打开

  技术分享

  2.在打开的Info.plist文件中点击“+”,添加新的字典,并命名为NSAppTransportSecurity

  技术分享

  3.打开NSAppTransportSecurity并添加NSAllowsArbitraryLoads类型Boolean,值设为YES

  技术分享

完成这三步之后回到项目,网络就可以正常访问了。

 

文章来自:http://www.cnblogs.com/htsh/p/4823200.html
© 2021 jiaocheng.bubufx.com  联系我们
ICP备案:鲁ICP备09046678号-3