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

  

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

 

posted @ 2015-09-20 12:28  核桃树之恋  阅读(637)  评论(0)    收藏  举报