iOS

iOS 13适配

2020-03-17  本文已影响0人  nuannuan_nuan

技术参考:

apple login

IOS13适配-详细

iOS 13 适配(持续更新中)

iOS13适配

掘金 iOS 13适配01

掘金 适配 iOS13

iOS 13 更新tips

View Controller Presentation Changes in iOS 13

1. Apple Login (2020年4月份)

附上官方Demo:下载地址

2. Dark Mode

2.1 暗黑模式 状态判断 && 切换监听

if (UITraitCollection.currentTraitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) {
    // 暗黑模式
}
else {
    // 正常模式
}

// 注意:参数为变化前的traitCollection
- (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection;

// 判断两个UITraitCollection对象是否不同
- (BOOL)hasDifferentColorAppearanceComparedToTraitCollection:(UITraitCollection *)traitCollection;

2.2 禁用暗黑模式

2.3 适配暗黑模式颜色

参考这里 :iOS开发如何适配暗黑模式(Dark Mode)

+ (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);

[UIColor colorWithDynamicProvider:^UIColor * _Nonnull(UITraitCollection * _Nonnull trait) {
    if (trait.userInterfaceStyle == UIUserInterfaceStyleDark) {
        return UIColorRGB(0x000000);
    } else {
        return UIColorRGB(0xFFFFFF);
    }
 }];

3. present 半屏问题

modalPresentationStyle属性默认不是UIModalPresentationFullScreen了,需要根据需求手动设置。

LXNavigationViewController *nav = [[LXNavigationViewController alloc] initWithRootViewController:loginViewController];
nav.modalPresentationStyle = UIModalPresentationFullScreen;
[self presentViewController:nav animated:YES completion:nil];

4. UITextField

UITextField 的私有属性 _placeholderLabel 被禁止访问了

[self.textField setValue:self.placeholderColor forKeyPath:@"_placeholderLabel.textColor"];

崩溃信息:

'Access to UITextField's _placeholderLabel ivar is prohibited. 
This is an application bug' 

UITextField有个attributedPlaceholder的属性,我们可以自定义这个富文本来达到我们需要的结果。

NSMutableAttributedString *placeholderString = [[NSMutableAttributedString alloc] initWithString:placeholder attributes:@{NSForegroundColorAttributeName : self.placeholderColor}];
_textField.attributedPlaceholder = placeholderString;

if (@available(iOS 13.0, *)) {
    if (textField.attributedText.length > 0) {
        color = textField.attributedText.color;
    }
}else{
    color = [textField valueForKeyPath:@"_placeholderLabel.textColor"];
}

iOS 13 通过 KVC 方式修改私有属性,有 Crash 风险,谨慎使用!并不是所有KVC都会Crash,要尝试!

5. UITextView 同上

6. navigationBar 使用UINavigation+SXFixSpace

if ([NSStringFromClass(subview.class) containsString:@"ContentView"]) {
    // 结构调整后 在这里return掉
    if (@available(iOS 13.0, *)) {
        if ([NSStringFromClass(subview.class) containsString:@"_UINavigationBarContentView"]) {
            return;
        }
    }

    //可修正iOS11之后的偏移
    subview.layoutMargins = UIEdgeInsetsMake(0, space, 0, space);break;
}

同时,下面的属性也已经被禁止访问了:

7. statusBar

// ios 13.0 之后,这个方法已经失效了
// [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];

- (UIStatusBarStyle)preferredStatusBarStyle {
    if (@available(iOS 13.0, *)){
        return UIStatusBarStyleDarkContent;
    }
    return UIStatusBarStyleDefault;
}

或者 ------>>:

UIStatusBarStyleDefault 替换为

(@available(iOS 13.0, *) ? UIStatusBarStyleDarkContent : UIStatusBarStyleDefault)

如果你还是使用的Xcode 10 为了走过编译器这一步,可以使用预编译命令,这么写:

#if defined(__IPHONE_13_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_13_0
    if (@available(iOS 13.0, *)) {
        [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDarkContent];
    }else{
        [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
    }
#else
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
#endif

8. UITabbar

9. UISearchBar

if ([subview isKindOfClass:NSClassFromString(@"UISearchBarBackground")]) {
    if (@available(iOS 13.0, *)) {
        subview.backgroundColor = [UIColor lightGrayColor];
        // subview.layer.contents = nil;
    }else{
        [subview removeFromSuperview];
    }
}

10. 增加一直使用蓝牙的权限申请

info.plist文件下
Key: NSBluetoothAlwaysUsageDescription
Value: 我们要一直使用您的蓝牙,具体做什么别问我

11. 推送 获取deviceToken

#include <arpa/inet.h>
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
    if (![deviceToken isKindOfClass:[NSData class]]) return;
    const unsigned *tokenBytes = [deviceToken bytes];
    NSString *hexToken = [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])];
    NSLog(@"deviceToken:%@",hexToken);
}

12. 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

参考:CNCopyCurrentNetworkInfo

13. APP 启动速度优化 导致frame获取失败

App启动过程中,部分View可能无法实时获取到frame。

14. WKWebView 中测量页面内容高度的方式变更

iOS 13以前 document.body.scrollHeight iOS 13中 document.documentElement.scrollHeight 两者相差55 应该是浏览器定义高度变了

15. fishhook 导致的Crash

github fishhook

16. MPMoviePlayerController 已经被弃用

'MPMoviePlayerController is no longer available. Use AVPlayerViewController in AVKit.' 

17. LaunchImage 即将消失

从 iOS 8 的时候,苹果就引入了 LaunchScreen,我们可以设置 LaunchScreen来作为启动页。当然,现在你还可以使用LaunchImage来设置启动图。不过使用LaunchImage的话,要求我们必须提供各种屏幕尺寸的启动图,来适配各种设备,随着苹果设备尺寸越来越多,这种方式显然不够 Flexible。而使用 LaunchScreen的话,情况会变的很简单, LaunchScreen是支持AutoLayout+SizeClass的,所以适配各种屏幕都不在话下。
注意啦⚠️,从2020年4月开始,所有使⽤ iOS13 SDK 的 App 将必须提供 LaunchScreen,LaunchImage即将退出历史舞台。

18. window层级变化

遍历视图获取 keywindow 的方式会失效。
新增了 screenWindow 自定义视图和 keywindow之间新增iOS 13系统的特有图层。

转自链接

关于iOS13更新的一些记录

更新日期说明

从2020年4月开始,提交给App Store的所有iPhone和iPad应用程序都必须使用iOS 13 SDK或更高版本构建。他们还必须支持iPhone X S Max或12.9英寸iPad Pro(第三代)或更高版本的全屏设计。

从2020年4月开始,所有使⽤ iOS13 SDK 的 App 将必须提供 LaunchScreen,LaunchImage即将退出历史舞台。

iOS 13 相关更新

借助iOS 13 SDK,您的应用程序可以利用黑暗模式,通过Apple登录,与CloudKit同步的Core Data,PencilKit等优势。您可以使用SwiftUI更快地构建动态用户界面,使用Combine编写现代事件处理代码,并使用UIKit创建iPad应用程序的Mac版本。

暗黑模式

使用iOS 13,用户可以切换到“暗模式”以将iOS转换为深色配色方案,将重点放在工作上,而控件则退到后台。有关将“暗模式”并入您的应用程序的信息。
适配具体详情请参考官方说明:外观定制

SwiftUI

SwiftUI是一种现代方法,可为iOS,macOS,watchOS和tvOS构建用户界面。使用基于组合的声明式编程,您可以比以往更快地构建动态接口。该框架提供了用于声明应用程序用户界面的视图,控件和布局结构。它还提供事件处理程序,用于向您的应用程序传递敲击,手势和其他类型的输入,并提供工具来管理从应用程序模型到用户将看到并与之交互的视图和控件的数据流。
具体可参看官方 SwiftUI 教程

Combine框架

Combine是一个新框架,提供了声明性的Swift API,用于随时间推移处理值。这些值可以表示用户界面事件,网络响应,计划的事件以及许多其他类型的异步数据。使用合并,可以声明发布者公开可以更改的值,以及订阅者从发布者那里接收这些值。组合通过集中事件处理代码并消除麻烦的技术(例如嵌套闭包和基于约定的回调),使您的代码更易于阅读和维护。

详情参看:Combine技术文档

使用Apple登录

使用Apple登录可以为人们提供一种快速,安全且隐私友好的方式,供人们设置帐户并开始使用您的应用程序和网站中的服务。

相关技术说明,可前往官方说明

关于使用Apple登录场景官方说明如下:

仅使用第三方或社交登录服务(例如Facebook登录,Google登录,Twitter登录,LinkedIn登录,Amazon登录或微信登录)的应用来设置或验证用户的主帐户该应用程序还必须提供“与Apple登录”作为等效选项。用户的主要帐户是他们与您的应用建立的帐户,用于识别自己,登录并访问您的功能和相关服务。

如果满足以下条件,则无需使用Apple登录:

更多iOS13更新说明可参考官方What’s New in the iOS SDK

关于iOS13和13.1 API变动的一些说明

更新API比较多,这里不做过多说明了。

更多可API更新说明可参考官方:

关于iOS13的发行说明

iOS和iPadOS 13.1发行说明

iOS13 注意事项特别说明:
[_textField setValue:[UIColor redColor] forKeyPath:@"_placeholderLabel.textColor"];//崩溃

[_textField setValue:[UIFont systemFontOfSize:14] forKeyPath:@"_placeholderLabel.font"];//崩溃

- (void)application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
    if (![deviceToken isKindOfClass:[NSData class]]) return;
    const unsigned *tokenBytes = (const unsigned *)[deviceToken bytes];
    NSString *hexToken = [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])];
    NSLog(@"deviceToken:%@",hexToken);
}

更多适配可参考:iOS13适配

Xcode 11更新简单说明

Xcode 11包括Swift 5.1和适用于iOS 13,tvOS 13,watchOS 6和macOS Catalina 10.15的SDK。

更多Xcode11更新可看:

Xcode 11发现说明

Xcode 11 使用体验可参考:

Xcode 11 初体验

转自

上一篇 下一篇

猜你喜欢

热点阅读