iOS 13 statusBarWindow on UIApplication: this code must be c

时间:2021-02-03 18:26:10

突然的崩溃让我措手不及

*** Terminating app due to uncaught exception ‘NSInternalInconsistencyException‘, reason: ‘App called -statusBar or -statusBarWindow on UIApplication: this code must be changed as there‘s no longer a status bar or status bar window. Use the statusBarManager object on the window scene instead.‘

 

修改方式

  if (@available(iOS 13.0, *)) {

             if (!_statusBar) {

                 // iOS 13  弃用keyWindow属性  从所有windowl数组中取

                 UIWindow *keyWindow = [UIApplication sharedApplication].windows[0];

                 _statusBar = [[UIView alloc] initWithFrame:keyWindow.windowScene.statusBarManager.statusBarFrame];

                 [keyWindow addSubview:_statusBar];

             }

}