禁用iOS9 App Transport Security(ATS)特性时不起作用
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)特性时不起作用的更多相关文章
- iOS9 Error Domain=NSURLErrorDomain Code=-1022 App Transport Security (ATS)
iOS 9在HTTP 访问时会出错 iOS9 Error Domain=NSURLErrorDomain Code=-1022 这时需要修改info.plist 文件 在Info.plist中添加N ...
- 关于iOS9中的App Transport Security相关说明及适配(转)
原文:http://my.oschina.net/vimfung/blog/494687 iOS9中新增App Transport Security(简称ATS)特性, 主要使到原来请求的时候用到的H ...
- 关于App Transport Security的更新,中英文对照 --Xcode 7 --iOS9
章节都为本人定义,无抄袭,其中英文部分内容为官方文档摘抄以及自己总结,翻译的不好,敬请指正 App Transport Security(暂且翻译为app传输安全) What is ATS? App ...
- 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 ...
- 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 ...
- 网络请求报错: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文 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- Don't Repeat Yourself (不要重复你自己)
DRY是指Don't Repeat Yourself特指在程序设计以及计算中避免重复代码,因为这样会降低灵活性.简洁性,并且可能导致代码之间的矛盾.<The Pragmatic Programm ...
- C#制作在线升级程序
//这是一个webservice private AppUpdate.UpdateServ UpdateSvr; private void button1_Click(object sender, S ...
- alternatives命令使用方法
alternatives命令使用方法 alternatives是Linux下的一个功能强大的命令.仅仅能在root权限下运行.如系统中有几个命令功能十分相似,却又不能任意删除,那么能够用 altern ...
- Ubuntu下多服务器 Rsync同步镜像服务配置
主服务器:192.168.5.13_ubuntu 从服务器:192.168.5.11_centos ================== 1> 在两台主机上分别安装rsync========== ...
- 文献阅读笔记——group sparsity and geometry constrained dictionary
周五实验室有同学报告了ICCV2013的一篇论文group sparsity and geometry constrained dictionary learning for action recog ...
- yii泛域名
return CMap::mergeArray( require (dirname(__FILE__) . '/main.php'), array( 'components' => array( ...
- Spark之路 --- Scala IDE Maven配置(使用开源中国的Maven库)和使用
为什么要使用Maven 摘自百度百科的介绍 Maven是基于项目对象模型(POM),可以通过一小段描述信息来管理项目的构建,报告和文档的软件项目管理工具.Maven 除了以程序构建能力为特色之外,还提 ...
- BeanDefinitionRegistry extends AliasRegistry
// 用该Registry注册一个新定义的bean,但是新的bean必须支持父的定义和子的定义void registerBeanDefinition(String beanName, BeanDefi ...
- ArcGIS: version not specified. You must call RuntimeManager.Bind before creat
打开program.cs把ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.EngineOrDesktop);这句放到Applicatio ...
- ASP.NET弹出模态对话框【转】
主页面 PageBase.aspx.cs 中的代码 protected void Page_Load(object sender, EventArgs e) { if (!this.IsPost ...