关于配置info.plist文件的https

在进行数据请求的时候,由于我依然用的http来请求,所以程序报错了:

错误报告:
2016-08-16 16:03:29.065 TheBlackListNet[3346:188988] 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.

2016-08-16 16:03:29.244 TheBlackListNet[3346:188843] Error Domain=NSURLErrorDomain Code=-1022 "The resource could not be loaded because the App Transport Security policy requires the use of a secure connection." UserInfo={NSUnderlyingError=0x7f9268cc1500 {Error Domain=kCFErrorDomainCFNetwork Code=-1022 "(null)"}, NSErrorFailingURLStringKey=http://XXX, NSErrorFailingURLKey=http://XXX, NSLocalizedDescription=The resource could not be loaded because the App Transport Security policy requires the use of a secure connection.}

出错原因:

这是因为在iOS9.0以后增加了APP Transport Security.将原来的Http转向了TLS1.2协议进行传输.这也就意味着原来的Http协议被强制使用了Https协议.

修正报错:打开info.plist文件,添加以下代码

<key>NSAppTransportSecurity</key><dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>

-------------注意----------------------

但有时候“修改info.plist文件”依然不行,因为在你的Xcode - TARGETS - Info - Custom iOS Target Properties中可能依然没有添加上‘上述代码’。所以你要添加上,再运行久OK.
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,948评论 18 139
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,372评论 25 708
  • 因为要结局swift3.0中引用snapKit的问题,看到一篇介绍Xcode8,swift3变化的文章,觉得很详细...
    uniapp阅读 4,512评论 0 12
  • 276期,感谢1组成员 【日精进打卡第89天】 【知~学习】 《六项精进》读0遍 共77遍 《六项精进》背0遍 共...
    周晨i阅读 245评论 0 0
  • 沃尔特总是让我想起菲利普,我顿了顿,想了想,是一个作者嘛,都是毛姆笔下的人物(亏了最近总吃核桃,脑子好用了不少~)...
    野草啊阅读 543评论 0 1