iOS网络请求错误解决方法

使用Xcode7及以上版本,打开以前的工程,网络请求不到数据,原因是: 
从iOS9开始引入了新特性App Transport Security (ATS),要求App内访问的网络必须使用HTTPS协议,但是现在很多项目使用的是HTTP协议,那么如何设置才能在iOS9中使用HTTP请求呢

需要在工程设置里添加以下内容:

<key>NSAppTransportSecurity</key>
    <dict>
        <key>NSAllowsArbitraryLoads</key>
        <true/>
    </dict> 
   
   
  • 1
  • 2
  • 3
  • 4
  • 5
  • 1
  • 2
  • 3
  • 4
  • 5

添加方法:

0

1

同样也可以这样添加:

Xcode7


在 Info.plist 中add Row添加 NSAppTransportSecurity 类型 Dictionary 

2

在 NSAppTransportSecurity 下添加 NSAllowsArbitraryLoads 类型 Boolean , 值设为 YES 

Xcode7.1


在Xcode7.1中苹果更改了这项设定的名称 
在 App Transport Security Settings 下添加 Allows Arbitrary Loads 类型 Boolean , 值设为 YES

3

1
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
iOS CoreData 一本好书,smartrookie ■ Chapter 1: Getting Started .................................................................................................................... 1 ■ Chapter 2: Understanding Core Data .................................................................................................. 27 ■ Chapter 3: Storing Data: SQLite and Other Options ............................................................................ 57 ■ Chapter 4: Creating a Data Model..................................................................................................... 107 ■ Chapter 5: Working with Data Objects ............................................................................................. 129 ■ Chapter 6: Refining Result Sets........................................................................................................181 ■ Chapter 7: Tuning Performance and Memory Usage........................................................................203 ■ Chapter 8: Versioning and Migrating Data ....................................................................................... 251 ■ Chapter 9: Using Core Data in Advanced Applications.....................................................................283 ■ Index:................................................................................................................................................359 Contents ■ About the Authors............................................................................................................................... xii ■ About the Technical Reviewer ........................................................................................................... xiii ■ Acknowledgments ............................................................................................................................. xiv ■ Introduction ..........................................................................................................................

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值