您的位置:首页 > 移动开发 > IOS开发

iOS 9 适配需要注意的问题

2015-09-23 10:09 281 查看

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. 实例化定位管理器
CLLocationManager *_locationManager = [[CLLocationManager alloc] init];
// 2. 设置代理
_locationManager.delegate = self;
// 3. 定位精度
[_locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
/**
* 4.请求用户权 限:分为:
*                  1`requestWhenInUseAuthorization只在前台开启定位
*                  2`requestAlwaysAuthorization在后台也可定位
* 注意:建议只请求1和2中的一个,如果两个权限都需要,只请求2即可
*12这样的顺序,将导致 bug:第一次启动程序后,系统将只请求1的权限,2的权限系统不会请求,只会在下一次启动应用时请 求2
*/
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];


同时必须配置 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出现“信任按钮”,



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



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



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



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

Mysteries of Auto Layout, Part 1

What's New in Storyboards

Implementing UI Designs in Interface Builder

Getting Started with Multitasking on iPad in iOS 9

Optimizing Your App for Multitasking on iPad in iOS
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: