2019-08-29 iOS13适配那点事

2019-9-20,apple公司向全球移动设备进行了iOS13系统正式版的推送。早上来到公司,之前在apple DDWC上就已经透露了iOS13系统会在今年的秋季跟大家见面,先来看看iOS13系统适配那点事。
1.访问私有属性造成崩溃的问题。
(1) [textField setValue:[UIColor colorWithHexString:colorStr] forKeyPath:@"_placeholderLabel.textColor"];
访问这种_placeholderLabel的,在iOS13系统上会造成崩溃问题。解决办法:写一个拓展,uitextfield+Utils 添加一个方式进行适配,在调用的时候,只替换一下方法就行。
(2) [[UIApplication sharedApplication] valueForKey:@"statusBarWindow" valueForKey:@"statusBar"]; 也是会崩溃的问题。iOS13处理办法 UIView *localStatusBar = [[UIApplication sharedApplication].keyWindow.window Scene.statusBarManager performSelector:@selector(createLocalStatusBar)]; UIView * statusBar = [localStatusBar performSelector:@selector(statusBar)];
(3)UISearchBar访问了私有属性@"UISearchBarBackground",并且removefromsuper.这样会导致崩溃的问题。
2.控制器的 modalPresentationStyle 默认值变了,之前是UIModalPresentationFullScreen这个默认值。 现在是这个默认值了UIModalPresentationAutomatic。
如何修改:
如果你完全接受苹果的这个默认效果,那就不需要去修改任何代码。
如果,你原来就比较细心,已经设置了modalPresentationStyle的值,那你也不会有这个影响。
对于想要找回原来默认交互的同学,直接设置如下即可:
self.modalPresentationStyle = UIModalPresentationFullScreen;
3.MPMoviePlayerController 在iOS 13已经不能用了,如果之前的项目是用这个播放器的话,那么在iOS13系统上是会崩溃的。则需要替换其他播放器来适配。
4.iOS 13 DeviceToken有变化,之前的获取DeviceToken是不能成功的。
适配方式如下,一下代码既能满足之前代码,也能满足现在iOS13的需求

  • (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);
    }
    5.Sign in with Apple (提供第三方登录的注意啦⚠️)
    如果你的应用使用了第三方登录或者社交登录,那么你也需要加下 「Sign in with Apple」🤪,苹果正式出击自己的地位了,在苹果手机上,你有第三方登录,为啥不能没有我的登录呢。哈哈

Sign In with Apple will be available for beta testing this summer. It will be required as an option for users in apps that support third-party sign-in when it is commercially available later this year.
如何集成可以查看 apple官网的,内部提供了一个demo。
6.即将废弃的 LaunchImage,这里需要怎么处理。有待更新

  1. Dark Mode 苹果iOS13系统,有个暗黑模式。在设置-显示与亮度-浅色/深色 两个模式进行选择。但是苹果并没有做强制要求一定要适配这种功能。但是处于这种模式,有些地方的在黑暗模式下,确实不太好看。可以考虑颜色的更改。
    处理方式:
  • (UIColor *)customColorWithDarkMode:(UIColor *)darkColor AndLightMode:(UIColor *)lightColor
    {
    if (@available(iOS 13.0, *)) {
    UIColor *custom_color = [UIColor colorWithDynamicProvider:^UIColor * _Nonnull(UITraitCollection * _Nonnull traitCollection) {
    if ([traitCollection userInterfaceStyle] == UIUserInterfaceStyleDark) {
    return darkColor;
    }else{
    return lightColor;
    }
    }];
    return custom_color;
    } else {
    // Fallback on earlier versions
    }
    }
    获取系统当前模式:colorWithDynamicProvider里面提供了[traitCollection userInterfaceStyle] == UIUserInterfaceStyleDark这个看当前的模式是哪个模式进行判断。哪些地方需要适配暗黑模式,则可以利用这个方法进行暗黑模式的适配。
    8.UIWebView替换为WKWebView,查看文档,("No longer supported; please adopt WKWebView.", ios(2.0, 12.0)),继续使用UIWebView是导致被拒的可能。
    9.期待大家的留言,有什么不足的大家可以提出来。
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容