iOS端Expo导出React Native应用启动闪黑屏问题求助
iOS Expo Ejected App: Black Screen Before Splash Screen on TestFlight
我最近碰到了和你一模一样的头疼问题,翻遍StackOverflow和GitHub议题踩了好多坑,终于整理出几个可行的排查和修复方向,分享给你:
核心问题分析
出现这种短暂黑屏间隙,大概率是窗口初始化重复覆盖或者启动页显示时机滞后导致的。看你的AppDelegate代码,非DEBUG模式下你先初始化了window并启动EXUpdates显示启动页,但在appController:didStartWithSuccess:回调里又调用了initializeReactNativeApp——这个方法里重新创建了window,直接替换掉了之前承载启动页的窗口,从而出现黑屏间隙。
修复方案
1. 避免重复创建UIWindow
修改initializeReactNativeApp方法,删掉重新实例化window的代码,复用已经创建好的window:
- (RCTBridge *)initializeReactNativeApp { RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:self.launchOptions]; RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge moduleName:@"main" initialProperties:nil]; rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1]; // 删掉重新创建window的代码,复用已有的self.window UIViewController *rootViewController = [[EXScreenOrientationViewController alloc] init]; rootViewController.view = rootView; self.window.rootViewController = rootViewController; // 不需要再次调用[self.window makeKeyAndVisible],之前已经设置过了 return bridge; }
2. 调整启动页服务的调用时机
在appController:didStartWithSuccess:回调里,确保先设置rootViewController,再调用启动页服务,同时增加实例有效性判断:
- (void)appController:(EXUpdatesAppController *)appController didStartWithSuccess:(BOOL)success { // 先初始化React Native并设置rootViewController appController.bridge = [self initializeReactNativeApp]; // 确认获取到有效的启动页服务实例 EXSplashScreenService *splashScreenService = (EXSplashScreenService *)[UMModuleRegistryProvider getSingletonModuleForClass:[EXSplashScreenService class]]; if (splashScreenService) { [splashScreenService showSplashScreenFor:self.window.rootViewController]; // 后续记得在React Native代码里调用SplashScreen.hideAsync()来隐藏启动页 } }
3. 再次确认XCode配置细节
- 打开XCode项目的General标签页,确认Deployment Info里的Launch Screen File确实选择了
SplashScreen.storyboard - 右键
SplashScreen.storyboard选择Open As > Source Code,检查是否有语法错误或资源引用失效的情况 - 清理XCode缓存:按
Command + Shift + K清理构建文件夹,再重新归档打包
4. 优化EXUpdates配置
如果你的应用开启了自动更新,调整app.json里的updates配置,避免等待更新超时导致黑屏:
{ "expo": { "updates": { "fallbackToCacheTimeout": 0, // 立即使用缓存版本,避免等待更新 "enableAutoUpdates": true } } }
额外排查点
- 尝试导出IPA后通过Ad Hoc安装测试,排除TestFlight打包过程的潜在影响
- 检查
SplashScreen.storyboard的背景色是否和rootView背景色一致,避免切换时出现颜色闪烁
内容的提问来源于stack exchange,提问作者Nick D
相关产品推荐
相关产品推荐

