iOS 9发布后,原来开发的iPad应用在iOS9下面测试时,协议使用的是HTTP,发送网络请求时,Console窗口输出:

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.

由上面的提示可以知道,ATS阻止了不安全的网络请求,为了使得我们的网络请求继续使用以前的HTTP协议(苹果现在建议使用HTTPS,所以建议尽快使用HTTPS来发送网络请求),按照上面的建议在Info.plist中添加了NSAppTransportSecurity为键的字典,其中包含一个键为NSAllowsArbitraryLoads值为Bool类型(设置为YES)的item,如图所示:

或者按照源码方式打开Info.plist文件并如下添加:

<key>NSAppTransportSecurity</key>

<dict>

  <key>NSAllowsArbitraryLoads</key>

  </true>

</dict>

重新编译,启动应用,发送网络请求,奇怪的是结果和之前完全一样,Console依然输出同样的警告信息,程序弹出窗口如下所示(与之前也完全相同):

到底原因在哪里啊?尝试了在iPhone上的应用,添加NSAppTransportSecurity字典到Info.plist之后是可以工作的,但是在iPad模拟器上还真机上却不能工作,到底为什么?

于是重新新建一个iPad应用工程,在iOS9下面通过HTTP协议请求百度主页“http://www.baidu.com”内容,在没有添加NSAppTransportSecurity字典时(也就是说没有禁止掉iOS9默认的ATS特性时)程序输出和上面一样的警告信息。此时在Info.plist上添加NSAppTransportSecurity字典禁用掉ATS特性,再次请求百度主页内容发现请求成功完成,那么很显然问题不在于iOS9模拟器,究竟是什么原因呢?

想到之前经常遇到一些资源类的内容改变之后不能在编译时及时得到反映的情况,决定把Info.plist文件先备份一份,之后删除掉Info.plist文件,重新编译程序后发现XCode报错,说缺少Info.plist文件,此时把备份的Info.plist文件恢复到原来的位置并再次添加到工程中,重新编译并启动应用再次通过HTTP协议发起网络请求,网络请求居然成功完成,看来问题在于原来的Info.plist文件内容的改变没有即时在编译的时候得到应用,或许XCode只是使用了之前的Info.plist文件(缓存的?)内容。

因此,当遇到修改了Info.plist文件内容后程序并没有表现出预想的行为的情况时,可以尝试备份Info.plist文件,然后删除原来的Info.plist编译程序,当出错之后,再次从备份的Info.plist文件恢复到原来的位置并添加到XCode中,重新编译,问题可能就会得到解决。

禁用iOS9 App Transport Security(ATS)特性时不起作用的更多相关文章

  1. iOS9 Error Domain=NSURLErrorDomain Code=-1022 App Transport Security (ATS)

    iOS 9在HTTP 访问时会出错  iOS9 Error Domain=NSURLErrorDomain Code=-1022 这时需要修改info.plist 文件 在Info.plist中添加N ...

  2. 关于iOS9中的App Transport Security相关说明及适配(转)

    原文:http://my.oschina.net/vimfung/blog/494687 iOS9中新增App Transport Security(简称ATS)特性, 主要使到原来请求的时候用到的H ...

  3. 关于App Transport Security的更新,中英文对照 --Xcode 7 --iOS9

    章节都为本人定义,无抄袭,其中英文部分内容为官方文档摘抄以及自己总结,翻译的不好,敬请指正 App Transport Security(暂且翻译为app传输安全) What is ATS? App ...

  4. IOS9网络请求报错:The resource could not be loaded because the App Transport Security policy requires the use of a secure connection.

    今天下载Xcode7试了下,运行项目时报上面的错误,网上查了下原来iOS9引入了新特性App Transport Security (ATS).详情:App Transport Security (A ...

  5. 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

    ios进行http请求,会出现这个问题: App Transport Security has blocked a cleartext HTTP (http://) resource load sin ...

  6. 网络请求报错: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 Transport Security (ATS) 如果你想设置不阻止任何网络,只需要在info.plist文 ...

  7. Xcode7 beta 网络请求报错:The resource could not be loaded because the App Transport Security policy requires the use of a secure connection.

    Xcode7 beta 网络请求报错:The resource could not be loaded because the App Transport Xcode7 beta 网络请求报错:The ...

  8. The resource could not be loaded because the App Transport Security policy requires the use of a secure connection.问题解决

    didFailLoadWithError(): Error Domain=NSURLErrorDomain Code=-1022 "The resource could not be loa ...

  9. Xcode7 beta 网络请求报错:The resource could not be loaded because the App Transport Security policy requir

          今天升级Xcode 7.0 bata发现网络访问失败.输出错误信息 The resource could not be loaded because the App Transport S ...

随机推荐

  1. MyBatis之三:多表联合查询

    在这篇文章里面主要讲解如何在mybatis里面使用一对一.一对多.多表联合查询(类似视图)操作的例子. 注:阅读本文前请先大概看一下之前两篇文章. 一.表结构 班级表class,学生表student, ...

  2. delphi TreeView修改选中的节点的颜色和背景

      TreeView修改选中的节点的颜色和背景     TCustomDrawTarget = (dtControl, dtItem, dtSubItem);   TCustomDrawStage = ...

  3. [AngularJS] $http cache

    By default your HTTP requests with the $https service in Angular are not cached. By setting some opt ...

  4. openstack 创建虚拟机

    http://blog.csdn.net/tantexian/article/details/44595885#comments

  5. Ruby on Rails Tutorial 第二章 之 toy_app项目搭建

    (第一章小结) 第一步:生成项目骨架 $ rails _4.1.6_ new toy_app 第二步:修改Gemfile 第三步:安装gem $ bundle install --without pr ...

  6. Link List

    At first, i prepared to go through <the introduction to algorithm> ,however , i found some par ...

  7. TortoiseGit安装教程

    TortoiseGit 是Windows下的可视化Git界面. 下载Git 网站地址: http://code.google.com/p/tortoisegit/ 安装前必须装上msysgit才能在W ...

  8. grep时排除指定的文件和目录

    参考:http://winterth.duapp.com/notes/ar03s04.htmlhttp://blog.sina.com.cn/s/blog_7169c8ce0100qkyf.html ...

  9. Jquery 之 日常积累(一)

    1.jquery函数在参数中传递 this,正确的写法: //页面中用 GetString(this); //脚本中定义 function GetString(obj){ var str = $(ob ...

  10. C语言第二节概述

    学前提醒 其实iOS开发就是开发iPhone\iPad上的软件,而要想开发一款软件,首先要学习程序设计语言 iOS开发需要学习的主要程序设计语言有:C语言.C++.Objective-C,其中C++. ...