《iOS13的特性和适配》

《iOS13的特性和适配》_第1张图片

Xcode11

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

iOS13的特性

众多新功能,随iOS13而来。

iOS13的适配

1. SceneDelegate

《iOS13的特性和适配》_第2张图片
  • 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
    《iOS13的特性和适配》_第3张图片
  • 注释掉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 *)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效果:

《iOS13的特性和适配》_第4张图片

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的特性和适配》_第5张图片

iOS13:


《iOS13的特性和适配》_第6张图片

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

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

《iOS13的特性和适配》_第7张图片


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
UIUserInterfaceStyle
Light

UIUserInterfaceStyle

  • 适配暗黑模式:
    《iOS13的特性和适配》_第8张图片

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


千里之行,始于足下。

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

你可能感兴趣的:(《iOS13的特性和适配》)