iOS 13 适配
原创 2019-06-28
iOS 13系统适配笔记。
截止目前,iOS 13发布到了beta 2。下面的适配笔记仅仅针对最新发布的系统,正式版本可能会有不同。将根据开发中发现的问题同步更新。
黑暗模式
通过UITraitCollection.currentTraitCollection.userInterfaceStyle获取当前模式。
iOS 13提供了内置的动态Color,会根据当前userInterfaceStyle自动显示不同的颜色。
UIColor *systemFillColor
UIColor *secondarySystemFillColor
UIColor *tertiarySystemFillColor
UIColor *quaternarySystemFillColor
更多的时候需要自定义动态颜色:
+ (UIColor *)colorWithDynamicProvider:(UIColor * (^)(UITraitCollection *))dynamicProvider API_AVAILABLE(ios(13.0), tvos(13.0)) API_UNAVAILABLE(watchos);
- (UIColor *)initWithDynamicProvider:(UIColor * (^)(UITraitCollection *))dynamicProvider API_AVAILABLE(ios(13.0), tvos(13.0)) API_UNAVAILABLE(watchos);
在回调中根据不同的userInterfaceStyle返回不同的颜色。
蓝牙权限说明
在iOS 13之前,想获取手机连接的蓝牙设备信息,可以直接使用:[CBCentralManager retrieveConnectedPeripheralsWithServices:],并不需要声明权限。
iOS 13之后,必须在Info.plist文件中增加NSBluetoothAlwaysUsageDescription说明,否则crash。
presentViewController的变化
在iOS 13之前,presentViewController展示的视图默认是全屏的,而在iOS 13中,变成了类似iPhone上写电子邮件的样式。
我们通常用modalTransitionStyle(控制转场过渡效果)和modalPresentationStyle(控制展示样式)修改模态弹出效果。其中modalPresentationStyle在iOS 13前默认为UIModalPresentationFullScreen,在iOS13中则是UIModalPresentationAutomatic。
CNCopyCurrentNetworkInfo的变化
CNCopyCurrentNetworkInfo接口会返回连接热点的名称和mac地址。从iOS 12开始,调用该函数将默认返回 nil,需要在Xcode中开启「Access WiFi Information」后才会返回正确的值。
iOS 13 中除开启「Access WiFi Information」以外,APP还需要符合下列三项条件中的至少一项,否则CNCopyCurrentNetworkInfo仍然返回nil:
- The app uses Core Location, and has the user’s authorization to use location information.
- The app uses the NEHotspotConfiguration API to configure the current Wi-Fi network.
- The app has active VPN configurations installed.
Sign With Apple实践
在iOS 13系统中,Apple要求提供第三方登录的APP也需要支持「Sign With Apple」,参考 iOS Sign With Apple实践。
dyld 3的变化
在iOS 13系统中,iOS将全面采用新的dyld 3以替代之前版本的dyld 2。dyld 3带来了可观的性能提升,较少了APP的启动时间。参考:iOS 13中dyld 3的改进和优化
UISegmentedControl的变化
iOS 13中重新修改了UISegmentedControl的UI样式,会有一点3D效果,视觉上更小。tintColor属性在UISegmentedControl上不会起作用,新增了selectedSegmentTintColor属性。
Launch images are deprecated
Launch images are deprecated in iOS 13.0. Use a launch storyboard or XIB instead.
SF Symbols
在iOS 13中,Apple为我们提供了大量的内置图标,我们可以使用UIImage(systemName: "")的接口获取,在macOS上提供了一个SF Symbols App,以便预览这些图标并获取其名称。Introducing SF Symbols
vpn设备文件的变化
iOS 13之前的vpn设备名称为utun1,iOS 13变更为utun2。此项变动可能会引起vpn状态判断的失效。
新增Diffable DataSource
UITableView和UICollectionView新增了Diffable DataSource的API,用于需要diff数据的情况。
相关文章:
iOS Crash log符号化
Address Sanitizer的原理和使用
iOS CLLocationManager的弹窗问题
iOS Asset Catalog and Bundle
iOS Sign With Apple实践
发表留言
您的电子邮箱地址不会被公开,必填项已用*标注。
留言板