iOS9 http不能访问网络——在Xcode中将https改成http方式

     

=====================2016-01-29更新===========================

   最近做demo时,发现将https改成http方式略有小变

  1. 没有改成http方式时输出的错误:

    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.

 2.修改的Info.plist添加文字有变:

 

 

 

 

 

========================== 分割线 ==========刘成利 EMail: liu_cheng_li@qq.com============

     九月底,随着iOS9的推送升级和Xcode7的发布。由于新的iOS9中,网络请求默认方式为Https,一种比原来Http更安全的协议方式。

      HTTPS(全称:Hyper Text Transfer Protocol over Secure Socket Layer),是以安全为目标的HTTP通道,简单讲是HTTP的安全版。即HTTP下加入SSL层,HTTPS的安全基础是SSL,因此加密的详细内容就需要SSL。

       对于iOS开发人员来说,项目开发中会产生网络访问失败。

      输出错误信息:The resource could not be loaded because the App Transport Security policy requires the use of a secure connection.


     这是因为  iOS9引入了新特性App Transport Security (ATS)。详情:苹果官网说明网址

     新特性要求App内访问的网络必须使用HTTPS协议。


    但是现在公司的项目使用的是HTTP协议,使用私有加密方式保证数据安全。现在也不能马上改成HTTPS协议传输。


 

最终找到以下解决办法:

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

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

   具体图文步骤如下:    NSAppTransportSecurity   NSAllowsArbitraryLoads 

  (注意:1.大部分项目是Info.plist,部分项目是其他名,例如我的下图项目是             TextCapital-info.plist

          2.单元测试下面也有一个Info.plist,修改那个文件是没有作用的!
       
        
   )

   NSAppTransportSecurity   NSAllowsArbitraryLoads




 

版权声明:本文为博主原创文章,未经博主允许不得转载。

 

posted @ 2015-10-07 20:53  刘成利的博客  阅读(12954)  评论(0编辑  收藏  举报