iOS9新特性

来源:互联网 发布:sql编程基础 编辑:程序博客网 时间:2024/05/18 10:38

一.iOS9网络适配:改用更安全的HTTPS

为了强制增强数据访问安全, iOS9 默认会把 所有的http请求 所有从NSURLConnection 、 CFURL 、 NSURLSession发出的 HTTP 请求,都改为 HTTPS 请求:iOS9.x-SDK编译时,默认会让所有从NSURLConnection 、 CFURL 、 NSURLSession发出的 HTTP 请求统一采用TLS 1.2 协议。因为 AFNetworking 现在的版本底层使用了 NSURLConnection ,众多App将被影响(基于iOS8.x-SDK的App不受影响)。服务器因此需要更新,以解析相关数据。如不更新,可通过在 Info.plist 中声明,倒退回不安全的网络请求。而这一做法,官方文档称为ATS,全称为App Transport Security,是iOS9的一个新特性。

一个符合 ATS 要求的 HTTPS,应该满足如下条件:

  1. Transport Layer Security协议版本要求TLS1.2以上
  2. 服务的Ciphers配置要求支持Forward Secrecy等
  3. 证书签名算法符合ATS要求等
如何适配:

方案一:立即让公司的服务端升级使用TLS 1.2,以解析相关数据。

方案二:虽Apple不建议,但可通过在 Info.plist 中声明,倒退回不安全的网络请求依然能让App访问指定http,甚至任意的http

在info.plist文件中添加:

 <key>NSAppTransportSecurity</key>

    <dict>

        <key>NSAllowsArbitraryLoads</key>

        <true/>

    </dict>



二.iOS9新特性:更灵活的后台定位

坏消息:如果不适配iOS9,就不能偷偷在后台定位(不带蓝条,见图)!

好消息:将允许出现这种场景:同一App中的多个location manager:一些只能在前台定位,另一些可在后台定位,并可随时开启或者关闭特定location manager的后台定位。

如果没有请求后台定位的权限,也是可以在后台定位的,不过会带蓝条。

如何偷偷在后台定位:请求后台定位权限:

<span style="font-size:14px;">// 1. 实例化定位管理器_locationManager = [[CLLocationManager alloc] init];// 2. 设置代理_locationManager.delegate = self;// 3. 定位精度[_locationManager setDesiredAccuracy:kCLLocationAccuracyBest];// 4.请求用户权限:分为:⓵只在前台开启定位⓶在后台也可定位,//注意:建议只请求⓵和⓶中的一个,如果两个权限都需要,只请求⓶即可,//⓵⓶这样的顺序,将导致bug:第一次启动程序后,系统将只请求⓵的权限,⓶的权限系统不会请求,只会在下一次启动应用时请求⓶if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8) {    //[_locationManager requestWhenInUseAuthorization];//⓵只在前台开启定位    [_locationManager requestAlwaysAuthorization];//⓶在后台也可定位}// 5.iOS9新特性:将允许出现这种场景:同一app中多个location manager:一些只能在前台定位,另一些可在后台定位(并可随时禁止其后台定位)。if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 9) {    _locationManager.allowsBackgroundLocationUpdates = YES;}// 6. 更新用户位置[_locationManager startUpdatingLocation];</span>

第一种解决方案:

配置info.plist文件:

<key>NSLocationAlwaysUsageDescription</key><string>请求后台定位权限</string><key>UIBackgroundModes</key><array>    <string>location</string></array>

第二种解决方案:

在对应 target 的 Capabilities -> Background Modes -> 开启 Location Updates



三.URLScheme适配:引入白名单概念

如果想一次性集成最常用的微信、新浪微博、QQ、支付宝四者的白名单,则配置如下:

<span style="font-size:14px;"><key>LSApplicationQueriesSchemes</key><array>    <!-- 微信 URL Scheme 白名单-->    <string>wechat</string>    <string>weixin</string>    <!-- 新浪微博 URL Scheme 白名单-->    <string>sinaweibohd</string>    <string>sinaweibo</string>    <string>sinaweibosso</string>    <string>weibosdk</string>    <string>weibosdk2.5</string>    <!-- QQ、Qzone URL Scheme 白名单-->    <string>mqqapi</string>    <string>mqq</string>    <string>mqqOpensdkSSoLogin</string>    <string>mqqconnect</string>    <string>mqqopensdkdataline</string>    <string>mqqopensdkgrouptribeshare</string>    <string>mqqopensdkfriend</string>    <string>mqqopensdkapi</string>    <string>mqqopensdkapiV2</string>    <string>mqqopensdkapiV3</string>    <string>mqzoneopensdk</string>    <string>wtloginmqq</string>    <string>wtloginmqq2</string>    <string>mqqwpa</string>    <string>mqzone</string>    <string>mqzonev2</string>    <string>mqzoneshare</string>    <string>wtloginqzone</string>    <string>mqzonewx</string>    <string>mqzoneopensdkapiV2</string>    <string>mqzoneopensdkapi19</string>    <string>mqzoneopensdkapi</string>    <string>mqzoneopensdk</string>    <!-- 支付宝  URL Scheme 白名单-->    <string>alipay</string>    <string>alipayshare</string></array></span><span style="font-size:18px;"></span>


四.新控件:UIStackView

UIStackView 栈视图, 类似AppleWatchGroup,父类:UIView

特点:

1.只能垂直或水平散列,因此不能完全取代Autolayout

2.能够快速的按顺序获取到子控件

3.批量修改间距更快

4.批量修改对齐方式最快


应用场景:

1.水平-标签,自定义TabBar

2.垂直-设置菜单


五.SafariServices

当我们的App需要显示网页内容,但是又不需要自定义这些内容的时候,直接使用SF,省事

<span style="font-size:14px;">SFSafariViewController *safariVC = [[SFSafariViewController alloc] initWithURL:[NSURL URLWithString:@"https://www.baidu.com"]];[self.navigationController pushViewController:safariVC animated:YES];</span>


0 0