• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ChenYilong/iOS9AdaptationTips: iOS9适配系列教程(iOS开发学习交流群: https://git ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

ChenYilong/iOS9AdaptationTips

开源软件地址:

https://github.com/ChenYilong/iOS9AdaptationTips

开源编程语言:

Objective-C 100.0%

开源软件介绍:

iOS9AdaptationTips( iOS开发学习交流群



iOS9适配系列教程【中文在页面下方

相关链接:iOS10适配系列教程

(截至2016年4月17日共有12篇,后续还将持续更新。更多iOS开发干货,欢迎关注 微博@iOS程序犭袁

中文快速导航:

  1. iOS9网络适配_ATS:改用更安全的HTTPS(见Demo1)
  2. WHAT(什么是SSL/TLS?跟HTTP和HTTPS有什么关系)
  3. WHY(以前的HTTP不是也能用吗?为什么要用SSL/TLS?Apple是不是又在反人类?)
  4. HOW(如何适配?---弱弱地问下:加班要多久?) 1. 第1种情况:HTTPS Only (只有HTTPS,所有情况下都使用ATS) 2. 第2种情况:Mix & Match(混合) 3. 第3种情况:Opt Out(禁用ATS) 4. 第4种情况:Opt Out With Exceptions(除特殊情况外,都不使用ATS) 4. Certificate Transparency
  5. Q-A
  6. iOS9新特性_更灵活的后台定位(见Demo2)
  7. 企业级分发
  8. iOS9以后,企业级分发ipa包将遭到与Mac上dmg安装包一样的待遇:默认不能安装,也不再出现“信任按钮”
  9. iOS9以后,企业分发时可能存在:下载的ipa包与网页两者的 bundle ID 无法匹配而导致下载失败的情况
  10. iOS9以后,企业APP安装之后,在网络情况为Wi-Fi环境的时候,可能会出现无法验证应用的情况
  11. Bitcode
  12. iOS9 URL Scheme 适配_引入白名单概念(见Demo3)
    1. 常见 URL Scheme
    2. Q-A
  13. iPad适配Slide Over 和 Split View
  14. 字体间隙变大导致 UI 显示异常
  15. 升级 Xcode7 后的崩溃与警告
  16. iOS9 下使用 Masonry 会引起崩溃的一种情况
  17. Xcode 升级后,旧的状态栏的样式设置方式会引起警告
    1. Demo4---navigationController状态栏样式新的设置方法
  18. Xcode7 在 debug 状态下也生成 .dSYM 文件引起的警告
  19. Xcode7 无法使用 8.x 系统的设备调试,一运行就报错 there is an intenal API error
  20. 使用了 HTML 的 iframe 元素可能导致无法从 Safari 跳转至 App
  21. iOS9锁屏控制台会打印警告
  22. Xcode7 上传应用时提示 ITMS-90535 Unable to publish iOS app with xxx SDK 的问题
  23. [在didFinishLaunchingWithOptions结束后还没有设置window的rootViewController会导致崩溃](https://github.com/ChenYilong/iOS9AdaptationTips#在didfinishlaunchingwithoptions结束后还没有设置window的rootview controller会导致崩溃)
  24. Demo5、Demo6--- 搜索 API
  25. iOS国际化问题:当前设备语言字符串返回有变化
  26. UITableView显示异常
  27. 代码创建的 tableView 无法隐藏 cell 分割线
  28. reloadData 刷新失效
  29. 基于 HTTP/2 的新 APNs 协议

English⬇️⬇️

For more infomation ,welcome to follow my twitter

Reference:iOS 10 Adaptation Tips

1. Demo1_You'd Better Convert HTTP to HTTPS

How to deal with the SSL in iOS9,One solution is as follows:

enter image description here

As Apple say :

enter image description here

enter image description here

enter image description here

iOS 9 and OSX 10.11 require TLSv1.2 SSL for all hosts you plan to request data from, unless you specify exception domains in your app's Info.plist file.

The syntax for the Info.plist configuration looks like this:

<key>NSAppTransportSecurity</key>
<dict>
  <key>NSExceptionDomains</key>
  <dict>
    <key>yourserver.com</key>
    <dict>
      <!--Include to allow subdomains-->
      <key>NSIncludesSubdomains</key>
      <true/>
      <!--Include to allow insecure HTTP requests-->
      <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
      <true/>
      <!--Include to specify minimum TLS version-->
      <key>NSTemporaryExceptionMinimumTLSVersion</key>
      <string>TLSv1.1</string>
    </dict>
  </dict>
</dict>

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

<key>NSAppTransportSecurity</key>
<dict>
    <!--Connect to anything (this is probably BAD)-->
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>

If you have to do this, it's probably best to update your servers to support TLSv1.2 and SSL. This should be considered a temporary workaround.

As of today, the prerelease documentation makes no mention of any of these configuration options in any specific way. Once it does, I'll update the answer to link to the relevant documentation.

Even though your sever supports TLSv1.2, you may also have to follow what I wrote above to ensure connecting successfully in iOS 9:

After some discussion with Apple Support, the issue is due to the self signed certificate.

ATS only trusts certificate signed by a well known CA, all others are rejected. As a consequence, the only solution with a Self signed certificate is to set an exception with NSExceptionDomains.

2.Demo2_iOS9 new feature in CoreLocation : backgroud when needed

If you're using CoreLocation framework in your app in Xcode7(pre-released), you may notice that there is a newly added property called allowsBackgroundLocationUpdates in CLLocationManager class.

This new property is explained in the WWDC session "What's New in Core Location". enter image description here

The default value is NO if you link against iOS 9.

If your app uses location in the background without showing the blue status bar, you have to set allowsBackgroundLocationUpdates to YES in addition to setting the background mode capability in Info.plist. Otherwise location updates are only delivered in foreground. The advantage is that, in the same app, you can now have some of the location managers update locations in background, while others at foreground. You can also reset the value to NO to change the behavior.

The documentation makes it pretty clear:

By default, this is NO for applications linked against iOS 9.0 or later, regardless of minimum deployment target.

With UIBackgroundModes set to include "location" in Info.plist, you must also set this property to YES at runtime whenever calling -startUpdatingLocation with the intent to continue in the background.

Setting this property to YES when UIBackgroundModes does not include "location" is a fatal error.

Resetting this property to NO is equivalent to omitting "location" from the UIBackgroundModes value. Access to location is still permitted whenever the application is running (ie not suspended), and has sufficient authorization (ie it has WhenInUse authorization and is in use, or it has Always authorization). However, the app will still be subject to the usual task suspension rules.

See -requestWhenInUseAuthorization and -requestAlwaysAuthorization for more details on possible authorization values.

Set Info.plist like this: enter image description here

The syntax for the Info.plist configuration looks like this:

<key>NSLocationAlwaysUsageDescription</key>
<string>微博@iOS程序犭袁 请求后台定位权限</string>

<key>UIBackgroundModes</key>
<array>
    <string>location</string>
</array>

Use like:

_locationManager = [[CLLocationManager alloc] init];
_locationManager.delegate = self;
[_locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8) {
    [_locationManager requestAlwaysAuthorization];
}
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 9) {
    _locationManager.allowsBackgroundLocationUpdates = YES;
}
[_locationManager startUpdatingLocation];

3.iOS 9 Dealing With Untrusted Enterprise Developer

Since iOS 9, there is no more “trust” option for an enterprise build.

Before iOS 9, there used to have an alert popped like this:

enter image description here

Now:

Users have to do the configuration themselves: Go to Settings - General - Profiles - tap on your Profile - tap on Trust button.

enter image description here

4.bitcode option

After Xcode 7, bitcode option is set enabled by default. If your library is complied without bitcode while the bitcode option is enabled in your project setting, you can

  1. Update your library with bit code, or you'll get warnings like:

(null): URGENT: all bitcode will be dropped because '/Users/myname/Library/Mobile Documents/comappleCloudDocs/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.

  1. Say NO to Enable Bitcode in your target Build Settings

enter image description here

and the Library Build Settings to remove the warnings

For more information,go to documentation of bitcode in developer library

,and WWDC 2015 Session 102: "Platforms State of the Union"

enter image description here

5.Privacy and Your App【URL scheme changes】

iOS 9 has made a small change to the handling of URL scheme. You must whitelist the url's that your app will call out by using the LSApplicationQueriesSchemes key in your Info.plist.

Please see the post here: http://awkwardhare.com/post/121196006730/quick-take-on-ios-9-url-scheme-changes

The main conclusion is that:

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.

The author also speculates that this is a bug with the OS and Apple will fix this in a subsequent release.

This is a new security feature of iOS 9. Watch WWDC 2015 Session 703 for more information.

enter image description here

Any app built with SDK 9 needs to provide an LSApplicationQueriesSchemes entry in its plist file, declaring which scheme it attempts to query.

<key>LSApplicationQueriesSchemes</key>
<array>
 <string>urlscheme</string>
 <string>urlscheme2</string>
 <string>urlscheme3</string>
 <string>urlscheme4</string>
</array> 

Assuming that we have two apps: Test A and Test B. TestB wants to check whether TestA is installed or not. "TestA" defines the following URL scheme in its info.plist file:

<key>CFBundleURLTypes</key>
<array>
	<dict>
		<key>CFBundleURLSchemes</key>
		<array>
			<string>testA</string>
		</array>
	</dict>
</array>

The second app "TestB" tries to find out if "TestA" is installed by calling:

[[UIApplication sharedApplication]
                    canOpenURL:[NSURL URLWithString:@"TestA://"]];

But this will generally return NO in iOS9, because "TestA" needs to be added to the LSApplicationQueriesSchemes entry in TestB's info.plist file. This is done by adding the following code to TestB's info.plist file:

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>TestA</string>
</array>

A working implementation can be found here: https://github.com/gatzsche/LSApplicationQueriesSchemes-Working-Example

6. Support Slide Over and Split View of iOS 9

enter image description here How to make an old project support Slide Over and Split View in iOS 9? You may find all the demo projects was written by storyboard or xib, but the older project's UI is written by code!

I would suggest switching to storyboards to make your life easy.

I would highly recommend you to watch the following WWDC videos and then think about what exactly you need to do in order to support multi tasking.

  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

7. UI Display Problem Due to Enlarged Character Space

iOS 9 introduced a new font of Chinese characters. The enlarged character space may cause display problems of text labels, especially for fixed label width. To avoid this, we prefer to use ‘sizeToFit’ and ‘ceilf’ methods to calculate label size dynamically.

8. Crash and Warnings

Sina SDK crashes on iOS 9 with the following information: Solution: update SDK. A case of Masonry crashing on iOS 9 left & leading, trailing & right: not equivalent any more. Some other modifications to make: Old way of setting status bar style lead to errors. Solution: delete ‘View controller-based status bar appearance’ key in ‘Info.plist’, apply new methods to set status bay style. Demo4 — set status bar style of navigationController If it still does not work after using the above method, the problem is probably on your rootViewController. Xcode 7 generates .dSYM file under debug circumstance and causes warnings. Solution: change debug setting. Prevent Xcode from generating .dSYM. Xcode 7 cannot debugging on 8.x devices. Solution: ensure the project name not including Chinese character. Problem of jumping between Safari and other apps. This is probably caused by using ‘iframe’ element in HTML. Warning when locking screen while executing tasks in apps. Haven’t found a solution. Crash when rootViewController not set in didFinishLaunchingWithOptions Solution: initialize rootViewController in didFinishLaunchingWithOptions and replace it afterwards.

9. Search API

Import related frameworks, and configure ‘search elements’ just as configuring tableview cells: Demo 6 shows how to combine CoreSpotlightSearch and tableView:

10. Change of Device Language Return String

Before iOS 9: the above code returns language string code (e.g. “zh-Hans”). iOS 9: returns language string code + area code (e.g. “zh-Hans-US"). Be careful when checking current language.

11. UITableView Display Problem

A project running well on Xcode 6 may encounter the following problems on Xcode 7:

  1. Tableview created by code cannot hide cell separators.
  2. reloadData does not work. For cell separators, we provide two solutions (the first one preferred): As for reloadData, we assume this may conflict with some new features. We can use local reload as an alternative:

License

Posted by 微博@iOS程序犭袁

Creative Commons BY-NC-ND 3.0

中文

1. Demo1_iOS9网络适配_ATS:改用更安全的HTTPS

[摘要]为了强制增强数据访问安全, iOS9 默认会把 所有的http请求 所有从NSURLConnectionCFURLNSURLSession发出的 HTTP 请求,都改为 HTTPS 请求:iOS9.x-SDK编译时,默认会让所有从NSURLConnectionCFURLNSURLSession发出的 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要求等

官方文档 App Transport Security Technote 对ATS 的介绍:

注:有童鞋反映:服务器已支持TLS 1.2 SSL ,但iOS9上还是不行,还要进行本文提出的适配操作。

那是因为:要注意 App Transport Security 要求 TLS 1.2,而且它要求站点使用支持forward secrecy协议的密码。证书也要求是符合ATS规格的,ATS只信任知名CA颁发的证书,小公司所使用的 self signed certificate,还是会被ATS拦截。。因此慎重检查与你的应用交互的服务器是不是符合ATS的要求非常重要。对此,建议使用下文中给出的NSExceptionDomains,并将你们公司的域名挂在下面。下文也会详细描述该问题。

官方文档 App Transport Security Technote 对CA颁发的证书要求:

Certificates must be signed using a SHA256 or better signature hash algorithm, with either a 2048 bit or greater RSA key or a 256 bit or greater Elliptic-Curve (ECC) key. Invalid certificates result in a hard failure and no connection

在讨论之前,跟往常一样,先说下iOS程序猿们最关心的问题:

跟我有毛关系?需要我加班吗?!

首先咱们来看下业内对Apple这一做法的评论:

enter image description here

这是某社交App上讨论,看来业内还是吐槽声和肯定声同在。

结论是:

跟你很有关系,加班吧,少年!

书归正传【严肃脸】,我们正式讨论下 WHAT,WHY,HOW:

  1. WHAT(什么是SSL/TLS?跟HTTP和HTTPS有什么关系)
  2. WHY(以前的HTTP不是也能用吗?为什么要用SSL/TLS?!Apple是不是又在反人类?)
  3. HOW(如何适配?---弱弱地问下:加班要多久?)

WHAT(什么是SSL/TLS?跟HTTP和HTTPS有什么关系)

什么是SSL/TLS? SSL你一定知道,在此不做赘述。主要说下什么是TLS,还有跟HTTP和HTTPS有什么关系。

TLS 是 SSL 新的别称:

“TLS1.0”之于“SSL3.1”,犹“公元2015”之于“民国104”,“一千克”之于“一公斤”:称呼不同,意思相同。

SSL 3.0版本之后的迭代版本被重新命名为TLS 1.0:TLS 1.0=SSL 3.1。所以我们平常也经常见到 “SSL/TLS” 这种说法。

目前,应用最广泛的是TLS 1.0,接下来是SSL 3.0。目前主流浏览器都已经实现了TLS 1.2的支持。

常用的有下面这些:

  • SSL 2.0
  • SSL 3.0
  • TLS 1.0 (SSL 3.1)
  • TLS 1.1 (SSL 3.1)
  • TLS 1.2 (SSL 3.1)

那为什么标题是“使用HTTPS”而没有提及SSL和TLS什么事? “SSL/TLS”跟HTTP和HTTPS有什么关系?

要理解这个,要看下他们之间的关系:

HTTP+SSL/TLS+TCP = HTTPS

HTTP+SSL/TLS+TCP

或者

HTTPS = “HTTP over SSL”

也就是说:

Apple让你的HTTP采用SSL/TLS协议,就是让你从HTTP转到HTTPS。而这一做法,官方文档称为ATS,全称为App Transport Security。

WHY(以前的HTTP不是也能用吗?为什么要用SSL/TLS?Apple是不是又在反人类?)

不使用SSL/TLS的HTTP通信,就是不加密的通信!

不使用SSL/TLS的HTTP通信,所有信息明文传播,带来了三大风险:

  1. 窃听风险(eavesdropping):第三方可以获知通信内容。
  2. 篡改风险(tampering):第三方可以修改通信内容。
  3. 冒充风险(pretending):第三方可以冒充他人身份参与通信。

SSL/TLS协议是为了解决这三大风险而设计的,希望达到:

  1. 所有信息都是加密传播,第三方无法窃听。
  2. 具有校验机制,一旦被篡改,通信双方会立刻发现。
  3. 配备身份证书,防止身份被冒充。

SSL/TLS的作用,打个比方来讲:

如果原来的 HTTP 是塑料水管,容易被戳破;那么如今新设计的 HTTPS 就像是在原有的塑料水管之外,再包一层金属水管(SSL/TLS协议)。一来,原有的塑料水管照样运行;二来,用金属加固了之后,不容易被戳破。

HOW(如何适配?---弱弱地问下:加班要多久?)

正如文章开头所说:

TLS 1.2 协议 强制增强数据访问安全 系统 Foundation 框架下的“相关网络请求”将不再默认使用 HTTP 等不安全的网络协议,而默认采用 TLS 1.2。服务器因此需要更新,以解析相关数据。如不更新,可通过在 Info.plist 中声明,倒退回不安全的网络请求。

总之:

要么咱们iOS程序猿加班,要么后台加班:

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

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

enter image description here

这也是官方文档和WWDC给出的解决方案:

  1. Apple官方文档

    该文章已有0人参与评论

    请发表评论

    全部评论

    上一篇:
    filsv/iOSDeviceSupport: Xcode iPhoneOS DeviceSupport files (6.0 - 15.4)发布时间:2022-06-21
    下一篇:
    ish-app/ish: Linux shell for iOS发布时间:2022-06-21
    热门推荐
    阅读排行榜

    扫描微信二维码

    查看手机版网站

    随时了解更新最新资讯

    139-2527-9053

    在线客服(服务时间 9:00~18:00)

    在线QQ客服
    地址:深圳市南山区西丽大学城创智工业园
    电邮:jeky_zhao#qq.com
    移动电话:139-2527-9053

    Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap