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

iOS9适配

2015-08-17 23:02 609 查看

iOS9适配

重要: iOS9之前提的需要适配的特性,前提是工程使用XCode7打包,所以目前App针对iOS9适配的事情是解决目前App版本在iOS9 beta版本的bug。因此,针对该前提条件,iOS9适配相关工作进行相关调整。

适配工作进度

目前分解为两步走:


1. Xcode6版本,进行iOS9适配测试


2. 打包平台切换到XCode7后,统一进行iOS9适配


Scheme涉及相关业务

Scheme适配建议:在工程中,有很多逻辑其实不需要使用canopenurl。

如果业务是主动调起某个App功能,直接调用openurl,如果返回NO,直接做相关处理,不需要使用canopenurl做判断。

如果业务需要先判断某个App是否支持某个openurl,根据判断结果做一些UI或者交互逻辑等业务处理,(目前我发现是分享业务是这样逻辑)。该情况又分为两种情况:

scheme是确定的,保持之前业务代码,不用做修改。

scheme是不确定,那么需要根据业务类型做调整。

QA同学根据下表,进行相关Sheme相关业务测试。

[thead]
[/thead]
Sheme业务备注
weixin分享到微信
weibo分享到微淘
laiwang分享到来往
mqq分享到qq
weibo分享到微博
QQ41C152CF分享到微信6.1
app
gamecenter
btaobao
还有些协议–业务是动态分配scheme的,比如TBUISelektonNavigater和windvane

iOS9适配梳理

iOS9 beta4版本Apple已经发布。目前iOS App 面临有几个问题需要适配和解决:



NSURLSession/NSURLConnection适配

CoreLocation适配

ShemeURL 适配

iOS-Universal-Framework-master适配XCode7



NSURLSession/NSURLConnection适配

名词解释:


ATS意思为App Transport Security(应用通讯安全)模式。





问题疑惑:


在使用iOS9 beta版本,目前线上的App的网络请求都是可以用,这个应用App的网络请求都是HTTP请求。难道苹果在iOS9 beta ATS是默认关闭的吗?这个有疑惑,需要进一步验证

接口升级

[thead]
[/thead]
API适用版本替代API
NSURLSessionConfigurationbackgroundSessionConfiguration7.0~8.49.0~ backgroundSessionConfigurationWithIdentifier
* 问题:iOS9系统默认NSURLSession使用STL,如果客户端依然使用HTTP请求,直接导致网络请求失败

[thead]
[/thead]
Item现象原因
1使用NSURLSession/NSURLConnection运行系统Log提示:
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.
iOS9 NSURLSession使用STL
2NSURLSessionDownloadTask的delegate error回调信息:
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=0x7fa9322198e0 {NSUnderlyingError=0x7fa9306be980 “The operation couldn’t be completed. (kCFErrorDomainCFNetwork error -1022.)”, NSErrorFailingURLStringKey=http://www.nasa.gov/sites/default/files/ladee_9.4.13_nasa_edge_0.jpg, NSErrorFailingURLKey=http://www.nasa.gov/sites/default/files/ladee_9.4.13_nasa_edge_0.jpg, NSLocalizedDescription=The resource could not be loaded because the App Transport Security policy requires the use of a secure connection.}
iOS9 NSURLSession使用STL
* 解决方案:

[thead]
[/thead]
Item解决方案成本
1网络安全的确是目前无线应用迫切面对的问题,如果资源充分,请直接服务端配合使用HTTPS,支持STL资源投入成本大
2. 对于App服务影响范围广,不可控
2修改工程.plist,对于不同场景,使用不同的.plist配置成本小;
2. 需要梳理具体对应的业务URL
* 细分AST .plist使用场景

[thead]
[/thead]
Item场景描述解决实例
1全部业务使用ATSApp全部网络请求使用NSURLSession, 放弃使用NSURLConnection
2部分业务不使用,其他全部业务使用ATS请看代码1
3只有指定业务使用ATS,其它业务都不支持ATS请看代码2
4完全不使用ATS请看代码3
5支持TSL,低版本请看代码4
代码1,解决该App其它业务支持ATS,只有www.nasa.gov和其相关子域名不支持ATS

<key>NSAppTransportSecurity</key>
    <dict>
        <key>NSExceptionDomains</key>
        <dict>
            <key>www.nasa.gov</key>
            <dict>
                <key>NSIncludesSubdomains</key>
                <true/>
                <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
                <true/>
            </dict>
        </dict>
    </dict>


* 代码2,解决App只有www.nasa.gov支持ATS,其它业务都不支持ATS*

<key>NSAppTransportSecurity</key>
    <dict>
        <key>NSAllowsArbitraryLoads</key>
        <true/>
        <key>NSExceptionDomains</key>
        <dict>
            <key>www.nasa.gov</key>
            <dict>
                <key>NSIncludesSubdomains</key>
                <false/>
                <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
                <false/>
            </dict>
        </dict>
    </dict>


代码3,解决App完全不使用ATS情景

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


代码4,支持ATS相关协议低版本

<key>NSAppTransportSecurity</key>
    <dict>
        <key>NSExceptionDomains</key>
        <dict>
            <key>www.nasa.gov</key>
            <dict>
                <key>NSExceptionRequiresForwardSecrecy</key>
                <false/>
                <key>NSExceptionMinimumTLSVersion</key>
                <string>TLSv1.1</string>
            </dict>
        </dict>
    </dict>


CoreLocation适配

问题:iOS9之后,App不能在后台偷偷进行定位数据采集;除非在设置中,明确标识有个选项,在程序后台开启定位。否则,iOS9上运行App,就会在手机上显示蓝带,强烈提示用户,App正在后台启动定位服务。请看下图

CoreLocation未适配的问题截图:


![enter image description here][1]

[1]:file:///Users/fangying/Desktop/CoreLocation-Problem.png =200

解决方案:

在info.plist中配置NSLocationAlwaysUsageDescription。添加这一项,会使在设置中增加程序Always的选项

![enter image1 description here][2]

[2]:file:///Users/fangying/Desktop/CoreLocation-Setting.png =200




2.由于App会有很多业务模块,不是所有业务模块都是需要后台定位的。所以从更好的用户体验考虑,更好的设计是,进入有后台定位业务模块时,开启后台定位,如果没有进入后台定位模块,则关闭后台定位。

allowsBackgroundLocationUpdates = YES or NO


URL scheme适配

URL scheme支持APP跳转到相关App的功能,比如App中有分享到微博,来往,旺信等功能,因此都要进行canOpenURL判断。如果iOS9不做适配,该功能就无法使用

[thead]
[/thead]
问题描述解决方案
canOpenURL: failed for URL: “myheh://com.bjtufang.mylocation” - error: “This app is not allowed to query for scheme myheh”在info.plist记入白名单,具体看如下代码
myheh:是加入到白名单的open ulr sheme

<key>LSApplicationQueriesSchemes</key>
    <array>
        <string>myheh</string>
    </array>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: