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

React Native iOS真机/模拟器白屏问题求助

React Native iOS白屏问题排查与修复

问题描述

Android真机/模拟器运行正常,iOS真机/模拟器启动后显示空白白屏,Metro服务已启动。关键错误日志包括:

  • Invariant Violation: Native module cannot be null.
  • Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication)
  • react-native-applovin-max循环引用警告
  • iOS端网络连接拒绝错误

相关日志

Metro服务日志

[Sat Jul 23 2022 19:21:25.140]  WARN     Require cycle: node_modules/react-native-applovin-max/src/index.js -> node_modules/react-native-applovin-max/src/AppLovinMAXAdView.js -> node_modules/react-native-applovin-max/src/index.js

Require cycles are allowed, but can result in uninitialized values. Consider refactoring to remove the need for a cycle.
[Sat Jul 23 2022 19:21:25.150]  ERROR    Invariant Violation: Native module cannot be null.
[Sat Jul 23 2022 19:21:25.150]  ERROR    Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication)
[Sat Jul 23 2022 19:21:25.150]  LOG      redux-persist/stateReconciler: rehydrated keys 'settings, session, deviceInfo, _persist'
[Sat Jul 23 2022 19:21:26.900]  ERROR    Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication)

Xcode日志

2022-07-23 06:51:21.227838-0700 myapps[1240:116275] [myTarget info] SDK autoinit started
2022-07-23 06:51:21.251646-0700 myapps[1240:116277] [myTarget info] SDK initialized
2022-07-23 06:51:21.277518-0700 myapps[1240:116039] [native] Running application myapps! ({
    initialProps =     {
    };
    rootTag = 1;
})

2022-07-23 06:51:21.292759-0700 myapps[1240:116277] 9.2.0 - [FirebaseAnalytics][I-ACS023007] Analytics v.9.2.0 started
2022-07-23 06:51:21.293125-0700 myapps[1240:116277] 9.2.0 - [FirebaseAnalytics][I-ACS023008] To enable debug logging set the following application argument: -FIRAnalyticsDebugEnabled 
2022-07-23 06:51:21.296473-0700 myapps[1240:116039] +[RNFBSharedUtils getConfigBooleanValue:key:defaultValue:] [Line 157] RNFBCrashlyticsInit crashlytics_debug_enabled via RNFBMeta: 0
2022-07-23 06:51:21.296499-0700 myapps[1240:116039] +[RNFBSharedUtils getConfigBooleanValue:key:defaultValue:] [Line 160] RNFBCrashlyticsInit crashlytics_debug_enabled final value: 0
2022-07-23 06:51:21.296512-0700 myapps[1240:116039] +[RNFBCrashlyticsInitProvider isCrashlyticsCollectionEnabled] [Line 49] RNFBCrashlyticsInit isCrashlyticsCollectionEnabled after checking crashlytics_debug_enabled: 0
2022-07-23 06:51:21.296529-0700 myapps[1240:116039] +[RNFBCrashlyticsInitProvider configureWithApp:] [Line 101] RNFBCrashlyticsInit initialization successful
2022-07-23 06:51:21.322156-0700 myapps[1240:116290] 9.2.0 - [FirebaseAnalytics][I-ACS800023] No pending snapshot to activate. SDK name: app_measurement
2022-07-23 06:51:21.334480-0700 myapps[1240:116276] 9.2.0 - [FirebaseAnalytics][I-ACS023012] Analytics collection enabled
2022-07-23 06:51:21.334738-0700 myapps[1240:116276] 9.2.0 - [FirebaseAnalytics][I-ACS023220] Analytics screen reporting is enabled. Call Analytics.logEvent(AnalyticsEventScreenView, parameters: [...]) to log a screen view event. To disable automatic screen reporting, set the flag FirebaseAutomaticScreenReportingEnabled to NO (boolean) in the Info.plist
2022-07-23 06:51:21.492619-0700 myapps[1240:116277] 9.2.0 - [FirebaseAnalytics][I-ACS025026] Deferring to Firebase for event data collection
2022-07-23 06:51:23.386157-0700 myapps[1240:116277] 9.2.0 - [FirebaseCrashlytics][I-CLS000000] Warning: NSUncaughtExceptionHandler is 'GADRegisterExceptionHandler' in '/private/var/containers/Bundle/Application/E7DB67AE-7139-49E5-B7BF-5CB022F7FF5E/myapps.app/myapps'
[Crashlytics] The signal SIGABRT has a non-Crashlytics handler (GADRegisterSignalHandlers).  This will interfere with reporting.
[Crashlytics] The signal SIGBUS has a non-Crashlytics handler (GADRegisterSignalHandlers).  This will interfere with reporting.
[Crashlytics] The signal SIGFPE has a non-Crashlytics handler (GADRegisterSignalHandlers).  This will interfere with reporting.
[Crashlytics] The signal SIGILL has a non-Crashlytics handler (GADRegisterSignalHandlers).  This will interfere with reporting.
[Crashlytics] The signal SIGSEGV has a non-Crashlytics handler (GADRegisterSignalHandlers).  This will interfere with reporting.
[Crashlytics] The signal SIGSYS has a non-Crashlytics handler (GADRegisterSignalHandlers).  This will interfere with reporting.
[Crashlytics] The signal SIGTRAP has a non-Crashlytics handler (GADRegisterSignalHandlers).  This will interfere with reporting.
2022-07-23 06:51:24.661576-0700 myapps[1240:116288] [javascript] '[ENV]', 'https://api.myapps.com'
2022-07-23 06:51:24.734493-0700 myapps[1240:116288] [javascript] Require cycle: node_modules/react-native-applovin-max/src/index.js -> node_modules/react-native-applovin-max/src/AppLovinMAXAdView.js -> node_modules/react-native-applovin-max/src/index.js

Require cycles are allowed, but can result in uninitialized values. Consider refactoring to remove the need for a cycle.
2022-07-23 06:51:24.742989-0700 myapps[1240:116288] [javascript] Invariant Violation: Native module cannot be null.
2022-07-23 06:51:24.747625-0700 myapps[1240:116288] [javascript] Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication)
2022-07-23 06:51:24.749831-0700 myapps[1240:116288] [javascript] redux-persist/stateReconciler: rehydrated keys 'settings, session, deviceInfo, _persist'
2022-07-23 06:51:24.781972-0700 myapps[1240:116277] [connection] nw_socket_handle_socket_event [C6:1] Socket SO_ERROR [61: Connection refused]
2022-07-23 06:51:24.782097-0700 myapps[1240:116285] [connection] nw_connection_get_connected_socket [C6] Client called nw_connection_get_connected_socket on unconnected nw_connection
2022-07-23 06:51:24.782117-0700 myapps[1240:116285] TCP Conn 0x282b51550 Failed : error 0:61 [61]
2022-07-23 06:51:24.846974-0700 myapps[1240:116039] [native] Running surface LogBox ({
    initialProps =     {
    };
    rootTag = 11;
})
2022-07-23 06:51:24.847370-0700 myapps[1240:116288] [javascript] Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication)
2022-07-23 06:51:25.848187-0700 myapps[1240:116039] [native] Failed to mount LogBox within 1s
2022-07-23 06:51:26.564688-0700 myapps[1240:116039] Preloading CNContactViewController
2022-07-23 06:51:26.577362-0700 myapps[1240:116039] [Graphics] UIColor created with component values far outside the expected range. Set a breakpoint on UIColorBreakForOutOfRangeColorComponents to debug. This message will only be logged once.

Chrome调试器日志截图

  • 日志截图1
  • 日志截图2
  • 日志截图3
  • 日志截图4

修复步骤

1. 清理缓存与重装依赖

执行以下命令彻底清理缓存和依赖:

rm -rf node_modules
rm package-lock.json yarn.lock
npm install # 或 yarn install
npx react-native start --reset-cache

2. 确保iOS原生模块正确链接

针对react-native-applovin-max及其他Native库:

cd ios
pod deintegrate
pod install
cd ..

手动验证Xcode配置:

  • 打开ios/myapps.xcworkspace
  • 检查Libraries目录下是否存在RNAppLovinMAX.xcodeproj
  • 进入项目Build Phases → Link Binary With Libraries,确认libRNAppLovinMAX.a已添加

3. 修复AppRegistry注册问题

检查项目入口文件(如index.js),确保App注册代码正确:

import { AppRegistry } from 'react-native';
import App from './App';
import { name as appName } from './app.json';

AppRegistry.registerComponent(appName, () => App);

同时确认Info.plist中的CFBundleDisplayName与app.json里的name完全一致。

4. 解决网络连接拒绝问题

  • 模拟器:确保Metro服务使用localhost,若失败替换为电脑局域网IP启动Metro:
    npx react-native start --host 你的局域网IP地址
    
  • 真机:手机与电脑需在同一局域网,启动Metro时指定局域网IP,同时检查Info.plist是否允许HTTP请求(若API为HTTP):
    新增以下配置到Info.plist:
    <key>NSAppTransportSecurity</key>
    <dict>
      <key>NSAllowsArbitraryLoads</key>
      <true/>
    </dict>
    

5. 排查react-native-applovin-max问题

  • 临时注释掉项目中对该库的所有引用,重新启动App,验证是否能正常加载
  • 若确认是该库导致,升级到最新版本:
    npm install react-native-applovin-max@latest
    cd ios && pod install && cd ..
    

内容的提问来源于stack exchange,提问作者Matrix

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.25 19:36:18