zoukankan      html  css  js  c++  java
  • iOS 9 适配需要注意的问题

    iOS 9 适配需要注意的问题

    1`网络适配_改用更安全的HTTPS

    iOS9把所有的http请求都改为https了:iOS9系统发送的网络请求将统一使用TLS 1.2 SSL。采用TLS 1.2 协议,目的是 强制增强数据访问安全,而且 系统 Foundation 框架下的相关网络请求,将不再默认使用 Http 等不安全的网络协议,而默认采用 TLS 1.2。服务器因此需要更新,以解析相关数据。如不更新,可通过在 Info.plist 中声明,倒退回不安全的网络请求。

    Info.plist 配置中的XML源码如下所示:

    NSAppTransportSecurity     

        NSExceptionDomains      yourserver.com                

        NSIncludesSubdomains                  

        NSTemporaryExceptionAllowsInsecureHTTPLoads                  

        NSTemporaryExceptionMinimumTLSVersion      TLSv1.1

    If your application (a third-party web browser, for instance) needs to connect to arbitrary hosts, you can configure it like this:

    NSAppTransportSecurity        

        NSAllowsArbitraryLoads

    声明:目前Apple的官方文档并未提及如何在 Info.plist 配置

    2`iOS9新特性_更灵活的后台定位

    1):在 iOS9上,如果不做适配,就不能偷偷在后台定位(不带蓝条).

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

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

    3):如何请求后台定位权限:

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

    同时必须配置 plist 文件,如下:

      NSLocationAlwaysUsageDescription       String  XXX 请求后台定位权限
      Required background modes                   Array
                          item0             App register for location updates.

    注:如果没配置Info.plist,100%你的程序会崩溃掉,并报错:

    *** Assertion failure in -[CLLocationManager setAllowsBackgroundLocationUpdates:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/CoreLocationFramework_Sim/CoreLocation-1808.1.5/Framework/CoreLocation/CLLocationManager.m:593

    3`Bitcode(在线版安卓ART模式)

    未来Watch应用须包含Bitcode,iOS不强制,但Xcode7默认会开启Bitcode。

    如何适配?

    方法一:更新library使包含Bitcode,否则会出现以下中的警告;

    (null): URGENT: all bitcode will be dropped because '/Users/myname/Library/Mobile Documents/com~apple~CloudDocs/foldername/appname/GoogleMobileAds.framework/GoogleMobileAds(GADSlot+AdEvents.o)' was built without bitcode. You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE), obtain an updated library from the vendor, or disable bitcode for this target. Note: This will be an error in the future.

    方法二:关闭Bitcode.

      Build Options -->>Enable BitCode   修改为:NO.

     

    4`企业级分发

    iOS9之前,企业级分发十分方便:点击App出现“信任按钮”,

    1.jpg

    iOS9以后,企业级分发ipa包将遭到与Mac上dmg安装包一样的待遇:默认不能安装,也不再出现“信任按钮”

    2.jpg

    必须让用户手动设置,如下:

    3.gif

    5`URL scheme

    在iOS9中,如果使用URL scheme必须在"Info.plist"中将你要在外部调用的URL scheme列为白名单,否则不能使用。key叫做LSApplicationQueriesSchemes ,键值内容是

    LSApplicationQueriesSchemes 

                urlscheme 

                urlscheme2 

                urlscheme3 

                urlscheme4

    推荐一篇博客: http://awkwardhare.com/post/121196006730/quick-take-on-ios-9-url-scheme-changes

    其中最关键的是以下部分:

    If you call the “canOpenURL” method on a URL that is not in your whitelist, it will return “NO”, even if there is an app installed that has registered to handle this scheme. A “This app is not allowed to query for scheme xxx” syslog entry will appear.If you call the “openURL” method on a URL that is not in your whitelist, it will fail silently. A “This app is not allowed to query for scheme xxx” syslog entry will appear.

    6`iPad适配Slide Over 和 Split View

    1.gif

    【iPad适配Slide Over 和 Split View】 若想适配multi tasking特性,唯一的建议:弃纯代码,改用storyboard、xib,纵观苹果WWDC所有Demo均是如此:

    1. Mysteries of Auto Layout, Part 1

    2. What's New in Storyboards

    3. Implementing UI Designs in Interface Builder

    4. Getting Started with Multitasking on iPad in iOS 9

    5. Optimizing Your App for Multitasking on iPad in iOS

  • 相关阅读:
    安装和使用git遇到的问题总结
    继承时,构造函数和析构函数的调用顺序
    c++文件的读写
    虚函数
    纯虚函数
    继承
    连接到github
    NDK无法包含std的头文件(string,list等)的解决方法
    Centos7.3安装maven并配置加速镜像源
    分享几个实用好看的WordPress主题(第二波)
  • 原文地址:https://www.cnblogs.com/lxthyme/p/4831394.html
Copyright © 2011-2022 走看看