You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Expo开发React Native时遭遇UIViewControllerBasedStatusBarAppearance警告

解决Expo React Native中状态栏警告问题

问题复盘

使用Expo学习React Native,处于React Navigation阶段,未主动修改状态栏却收到警告:

If you want to change the appearance of status bar, you have to change UIViewControllerBasedStatusBarAppearance key in the Info.plist to YES

已在app.json的ios节点下添加infoPlist配置,但警告仍存在,且状态栏功能正常。

解决步骤

1. 确认app.json配置层级正确

确保配置嵌套在expo -> ios -> infoPlist下,完整结构示例:

{
  "expo": {
    "name": "你的项目名",
    "slug": "项目slug",
    "ios": {
      "infoPlist": {
        "UIViewControllerBasedStatusBarAppearance": true
      }
    }
  }
}

若层级错误,配置不会被Expo正确读取。

2. 清除Expo缓存

缓存可能导致新配置未生效,执行命令清除缓存并重启项目:

expo r -c

也可手动删除项目根目录的.expo文件夹后重启。

3. 检查react-native-screens兼容性

日志中出现RNScreensTurboModule相关报错,说明该库是警告来源。确保其版本与当前Expo SDK兼容,执行命令更新到适配版本:

expo install react-native-screens

4. 显式配置状态栏(可选)

虽然状态栏功能正常,但显式通过代码配置可消除警告。使用Expo官方的StatusBar组件:

import { StatusBar } from 'expo-status-bar';

export default function App() {
  return (
    <>
      <StatusBar style="auto" />
      {/* 你的页面组件 */}
    </>
  );
}

5. 裸工作流需预构建项目

若已切换到裸工作流,需重新预构建iOS项目使infoPlist修改生效:

expo prebuild --platform ios

内容的提问来源于stack exchange,提问作者alex.thry

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.23 05:07:22