2

在我的应用程序中,我使用 React Native(遗留代码)和 iOS 原生组件。

最近我preferredStatusBarStyle在我的 iOS ViewController 中实现了覆盖。

但在 Info.plist 中preferredStatusBarStyle不起作用。View controller-based status bar appearance = YES所以我把这个键改成了YES。

现在我有一个 React Native 错误:“RCTStatusBarManager 模块要求 Info.plist 中的 UIViewControllerBasedStatusBarAppearance 键设置为 NO”

错误截图。

有什么方法可以在不更改 .plist 的情况下消除错误?我搜索了所有遗留的反应代码,没有发现任何使用StatusBarReact Component

4

1 回答 1

4

preferredStatusBarStyle由于 React Native 错误,我无法通过使用modern 来解决这个问题。但是这种设置状态栏样式的旧方法有所帮助:UIApplication.shared.setStatusBarStyle().

我写了这个助手来改变我的应用程序中的 statusBar 样式:

public static func updateStatusBarStyle(isLightBackground: Bool) {
  var statusBarStyle: UIStatusBarStyle
  if isLightBackground, #available(iOS 13.0, *) {
    statusBarStyle = .darkContent
  } else {
    statusBarStyle = isLightBackground ? .default : .lightContent
  }
  UIApplication.shared.setStatusBarStyle(statusBarStyle, animated: true)
}
于 2021-05-09T08:17:04.697 回答