《iOS13的特性和适配》

Xcode11

【WWDC2019 Session】Xcode 11新特性
Xcode官方文档

iOS13的特性

众多新功能,随iOS13而来。

iOS13的适配

1. SceneDelegate

  • In iOS 13 and later, use UISceneDelegate objects to respond to life-cycle events in a scene-based app.
  • In iOS 12 and earlier, use the UIApplicationDelegate object to respond to life-cycle events.

Q: 基于Xcode11新建的工程,在iOS13以前的版本不展示window,如何解决?
A:在AppDelegate.h 中添加window:

@property (strong, nonatomic) UIWindow *window;
  • 如果不使用场景功能,在info.plist文键中删除Application Scene Manifast
  • 注释掉AppDelegate中 UISceneSession lifecycle
//- (UISceneConfiguration *)application:(UIApplication *)application configurationForConnectingSceneSession:(UISceneSession *)connectingSceneSession options:(UISceneConnectionOptions *)options {
//    // Called when a new scene session is being created.
//    // Use this method to select a configuration to create the new scene with.
//    return [[UISceneConfiguration alloc] initWithName:@"Default Configuration" sessionRole:connectingSceneSession.role];
//}
//
//
//- (void)application:(UIApplication *)application didDiscardSceneSessions:(NSSet<UISceneSession *> *)sceneSessions {
//    // Called when the user discards a scene session.
//    // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
//    // Use this method to release any resources that were specific to the discarded scenes, as they will not return.
//}

2. 不允许使用 valueForKeysetValue: forKey 获取和设置私有属性;

// crash代码 
[tf setValue:[UIColor greenColor] forKeyPath:@"_placeholderLabel.textColor"];
[tf setValue:[UIFont systemFontOfSize:12.f] forKeyPath:@"_placeholderLabel.font"];

// 修复代码
tf.attributedPlaceholder = [[NSMutableAttributedString alloc] initWithString:tf.placeholder attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12.f],NSForegroundColorAttributeName:[UIColor redColor]}];

(注意: 使用富文本修改placeholder时, tf.placeholder不能为空.)

// crash代码
UIButton *cancelBtn = [searchBar valueForKey:@"_cancelButton"];

// 修复代码 (不建议)
UIButton *cancelBtn = [searchBar valueForKey:@"cancelButton"];

// 获取状态栏视图 crash
UIView *statusBar = [[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"];

3. 控制器的 modalPresentationStyle 新增UIModalPresentationAutomatic, 且在iOS13上被设置为默认值;

iOS13效果:


1). 如果使用此效果模式, 需要适配页面布局, 否则底部内容会被遮挡;
2). 如果不使用, 修改控制器的 modalPresentationStyle为其他值.
(注意: 系统类如发送短信修改style无效.)


4. 之前标记为 API_DEPRECATED 部分类被移除

  • MPMoviePlayerController ==> AVPlayerViewController

  • UISearchDisplayController ==> UISearchController

  • UIAlertView

5. Sign in with Apple

  • 使用 Sign in with Apple 会更加方便、快捷、安全,苹果不会追踪用户在应用中的行为。所以,对于用户来说使用 Sign in with Apple 会更加安全。
  • App 没有提供第三方登录,不需要集成。如果用到了第三方登录,那么需要提供 Sign in with Apple,而且必须放在最前面。
    集成 Sign in with Apple 功能.

6. 即将废弃的 LaunchImage

iOS 8 之前我们是在 LaunchImage 来设置启动图,但是随着苹果设备尺寸越来越多,我们需要在对应的 aseets 里面放入所有尺寸的启动图,这是非常繁琐的一个步骤。因此在 iOS 8 苹果引入了 LaunchScreen.storyboard,支持界面布局用的 AutoLayout + SizeClass ,可以很方便适配各种屏幕。

需要注意的是,苹果在 Modernizing Your UI for iOS 13 section 中提到
,从2020年4月开始,所有支持 iOS 13 的 App 必须提供 LaunchScreen.storyboard,否则将无法提交到 App Store 进行审批。


7. DeviceToken 获取

// 以前的
- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken {
    /// Required - 注册 DeviceToken
    [JPUSHService registerDeviceToken:deviceToken];
}
// iOS13
- (void)application:(UIApplication *)application
    didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
  const unsigned int *tokenBytes = [deviceToken bytes];
  NSString *tokenString = [NSString stringWithFormat:@"%08x%08x%08x%08x%08x%08x%08x%08x",
                        ntohl(tokenBytes[0]), ntohl(tokenBytes[1]), ntohl(tokenBytes[2]),
                        ntohl(tokenBytes[3]), ntohl(tokenBytes[4]), ntohl(tokenBytes[5]),
                        ntohl(tokenBytes[6]), ntohl(tokenBytes[7])];
  rootViewController.deviceTokenValueLabel.text = tokenString;
  rootViewController.deviceTokenValueLabel.textColor =
      [UIColor colorWithRed:0.0 / 255
                      green:122.0 / 255
                       blue:255.0 / 255
                      alpha:1];
  NSLog(@"Device Token: %@", tokenString);
  [JPUSHService registerDeviceToken:deviceToken];
}

https://developer.umeng.com/docs/66632/detail/126489


8. UISegmentedControl 默认样式改变

iOS13以前:


iOS13:



9. 蓝牙需要新增权限描述

iOS13 以后废弃 NSBluetoothPeripheralUsageDescription,
iOS13新增 NSBluetoothAlwaysUsageDescription;


10. 废弃UIWebview APIs

从 iOS13 开始苹果将 UIWebview 列为过期API。 目前提交苹果应用市场(App Store)会反馈以下邮件提示:

ITMS-90809: Deprecated API Usage - Apple will stop accepting submissions of apps that use UIWebView APIs .
See developer.apple.com/documentati… for more information.


11. CNCopyCurrentNetworkInfo 变化

 An app that fails to meet any of the above requirements receives the following return value:

- An app linked against iOS 12 or earlier receives a dictionary with pseudo-values. In this case, the SSID is Wi-Fi (or WLAN in the China region), and the BSSID is 00:00:00:00:00:00.
- An app linked against iOS 13 or later receives NULL.

iOS13 以后只有开启了 Access WiFi Information capability,才能获取到 SSID 和 BSSID


12. Dark Mode

Apps on iOS 13 are expected to support dark mode
Use system colors and materials
Create your own dynamic colors and images Leverage flexible infrastructure

  • 不适配暗黑模式情况下处理方式:
方法一: 修改代码
if (@available(iOS 13.0, *)) {
    [UIApplication sharedApplication].keyWindow.overrideUserInterfaceStyle = UIUserInterfaceStyleLight;
} 

方法二: 修改info.plist
<key>UIUserInterfaceStyle</key>
<string>Light</string>

UIUserInterfaceStyle

  • 适配暗黑模式:

使用 QMUITheme 实现换肤并适配 iOS 13 Dark Mode


千里之行,始于足下。

参考文档:
【WWDC2019 Session】Xcode 11新特性
Xcode官方文档
众多新功能,随iOS13而来。
集成 Sign in with Apple 功能.
适配 iOS13(持续更新)
使用 QMUITheme 实现换肤并适配 iOS 13 Dark Mode

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 199,830评论 5 468
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 83,992评论 2 376
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 146,875评论 0 331
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 53,837评论 1 271
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 62,734评论 5 360
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,091评论 1 277
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,550评论 3 390
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,217评论 0 254
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,368评论 1 294
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,298评论 2 317
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,350评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,027评论 3 315
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,623评论 3 303
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,706评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,940评论 1 255
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,349评论 2 346
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 41,936评论 2 341

推荐阅读更多精彩内容

  • 因为要结局swift3.0中引用snapKit的问题,看到一篇介绍Xcode8,swift3变化的文章,觉得很详细...
    uniapp阅读 4,377评论 0 12
  • 推荐文章 iOS Swift 自定义导航栏 FLNavigationBar 解决所有问题 WWDC 2019 Xc...
    松花蛋蘸醋阅读 2,872评论 1 9
  • 我啊,真的挺幸福的。 今天我哥给我买了一千多块钱的衣服,说不感动是假的,我真的很幸福。 我哥是...
    陌漠小姐阅读 55评论 0 1
  • 昨天本是日更的第七天,我没有更文字,复活卡被用掉了。日更这件事情因为不是生活的必需品,所以一点小情绪小事情,它就被...
    巫格娅尔阅读 137评论 0 1
  • 一天都没时间运动,晚上下班回家步行。到家放下手上带的东西,立马又去军校广场给孩子买东西,这样算是运动吧!
    冰雪嫣然阅读 100评论 0 0