iOS 13 适配 (填坑...)

1.私有API被封禁(KVC限制),禁止访问.

iOS13中通过KVC方式来获取私有属性,有Carsh风险,尽量避免使用.比如我们常用的UITextFiled和UISearchController等,在iOS 13的searchbar添加了一个- (void)set_cancelButtonText:(NSString *)text方法,这个方法专门用来命中kvc,一旦命中就Crash。


//修改textField的占位符字体颜色
[textField setValue:[UIColor xxx] forKeyPath:@"_placeholderLabel.textColor"];

(1).获取SearchBar的textField

由于在13中把SearchBar中的textField直接暴露给开发者使用,无需在通过kvc获取。


- (UITextField *)sa_GetSearchTextFiled{
    if ([[[UIDevice currentDevice]systemVersion] floatValue] >= 13.0) {
        return self.searchTextField;
    }else{
        UITextField *searchTextField =  [self valueForKey:@"_searchField"];
        return searchTextField;
    }
}

(2).修改TextFiled的占位符字体大小以及颜色,在iOS13中不能通过KVC来进行修改,可以通过其属性字符串来进行修改

UITextField *textfield = [[UITextField alloc]init];
NSMutableAttributedString *arrStr = [[NSMutableAttributedString alloc]initWithString:textfield.placeholder attributes:@{NSForegroundColorAttributeName : [UIColor redColor],NSFontAttributeName:[UIFont systemFontOfSize:12]}];
textfield.attributedPlaceholder = arrStr;



(3).获取SearchBar的cancleButton,由于searcBar的层级发生变化以及对象的局部变量,因为无法通过kvc的方式来获取


if ([[[UIDevice currentDevice]systemVersion] floatValue] >= 13.0) {
          for(id cc in [self.searchBar subviews]) {
              for (id zz in [cc subviews]) {
                  for (id gg in [zz subviews]) {
                      if([gg isKindOfClass:[UIButton class]]){
                          UIButton *cancelButton = (UIButton *)gg;
                          [cancelButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
                      }
                  }
              }

          }
      }else{
          UIButton*cancelButton = (UIButton *)[self.searchBar getVarWithName:@"_cancelButton"];
          [cancelButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
      }



2.MPMoviePlayerController在iOS13中废弃

MPMoviePlayerController is no longer available. Use AVPlayerViewController in AVKit.
在iOS13中对于MPMoviePlayerController使用的废弃,需要使用AVKit中的AVPlayerViewController来达到播放的目的。

3.Sign in with Apple 第三方登录

当 Sign In with Apple 服务正式上线以后,所有已接入其它第三方登录的 App,Sign In with Apple 将被要求作为一种登录选择,否则有可能就不给过。如果 APP 支持三方登陆(Facbook、Google、微信、QQ、支付宝等),就必须支持苹果登录,且要放前边。解决方法:未来上线之后,添加登录入口即可。

4.即将废弃的 LaunchImage

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

5.模态弹出默认交互改变

iOS 13 的 presentViewController 默认有视差效果,模态出来的界面现在默认都下滑返回。 一些页面必须要点确认才能消失的,需要适配。如果项目中页面高度全部是屏幕尺寸,那么多出来的导航高度会出现问题。


// Swift
self.modalPresentationStyle = .fullScreen
// Objective-C
self.modalPresentationStyle = UIModalPresentationFullScreen;

UIViewController 增加一个了属性 isModalInPresentation,默认为 false,当该属性为 false 时,用户下拉可以 dismiss 控制器,为 true 时,下拉不可以 dismiss控制器。

6.UISegmentedControl 默认样式改变

默认样式变为白底黑字,如果设置修改过颜色的话,页面需要修改

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

CBCentralManager,iOS13以前,使用蓝牙时可以直接用,不会出现权限提示,iOS13后,再使用就会提示了。在info.plist里增加NSBluetoothAlwaysUsageDescription 我们要一直使用您的蓝牙,具体做什么别问我

8.废弃 UISearchDisplayController

在 iOS 8 之前,我们在 UITableView 上添加搜索框需要使用 UISearchBar + UISearchDisplayController 的组合方式,而在 iOS 8 之后,苹果就已经推出了 UISearchController 来代替这个组合方式。在 iOS 13 中,如果还继续使用 UISearchDisplayController 会直接导致崩溃,

9.修改StatusBar的颜色

创建一个 UIView *_statusBar;
在页面消失时置位nil,不影响其他页面。
- (void)viewWillDisappear:(BOOL)animated {
 [super viewWillDisappear:animated];
 if (@available(iOS 13.0, *)) {
     [_statusBar removeFromSuperview];
     _statusBar = nil;
 }
}


if (@available(iOS 13.0, *)) {
     if (!_statusBar) {
         _statusBar = [[UIView alloc] initWithFrame:[UIApplication sharedApplication].statusBarFrame];
         [[UIApplication sharedApplication].keyWindow addSubview:_statusBar];
     }

 } else {
     
   _statusBar = [[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"];
}
 

 if ([_statusBar respondsToSelector:@selector(setBackgroundColor:)]) {
     _statusBar.backgroundColor = color;
 }

未完待续…

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章