问题描述::
我正在使用react-native-ios应用程序,大多数情况下它在启动后卡住了。我在我的本机代码中创建了一个重复的初始屏幕。应用启动时,我将其重定向到虚拟启动屏幕,这与启动完全一样。在这里,我正在从API加载应用程序的完整必需数据。加载完整数据后,我将其推入初始屏幕。但是大多数时候,我在启动画面后卡住了,或者有时在加载启动画面后崩溃了(当从原始启动画面移动到要加载整个应用程序所需数据的虚拟启动画面时)。
[终端内部没有错误,每当我的应用崩溃或应用停留在启动屏幕时,我都会在xcode输出窗口中收到以下提到的错误。
错误::
由于未捕获的异常而终止应用程序“ NSInternalInconsistencyException”,原因:“应用程序窗口为预计在应用程序末尾具有根视图控制器启动”
libc ++ abi.dylib:以类型未捕获的异常终止NSException
如果我将我重定向到登录屏幕,但我的iOS应用运行正常,但是每当我重定向到虚拟启动时都会出现问题。我也将虚拟屏幕名称更改为“ initializer.js”,但没有任何反应。 iOS应用程序在启动后崩溃或卡住,将其重定向到我正在加载应用程序所需的完整数据的屏幕。
App Intializer屏幕代码(虚拟飞溅)::
/** * Splash Screen */ import React, { useEffect } from 'react'; import { connect } from 'react-redux'; import * as Animatable from 'react-native-animatable'; import { View, Text } from 'react-native'; import { Spinner } from 'native-base'; import Toast from 'react-native-simple-toast'; import NetInfo from '@react-native-community/netinfo'; import SplashScreen from 'react-native-splash-screen'; import AsyncStorage from '@react-native-community/async-storage'; //Global Components import { ImageView } from '../../Components/GlobalComponent'; //Form Components import { Button } from '../../Components/FormComponent'; // APIResponseMessages import APIResponseMessages from '../../Constants/APIResponseMessages'; // Actions import { appInitialize, loader } from '../../Actions'; //Style import { GlobalStyles, Colors } from '../../Styles'; //Images import Images from '../../Assets/Images'; //Navigation Screen import { AUTH, INITIAL_SCREEN, setRootScreen } from '../../Navigation'; import LocalStorageKeys from '../../Constants/LocalStorageKeys'; // singleton class import APIURLServiceSingleton from '../../Services/APIURLService'; // Strings import { en } from '../../Strings'; //Base Controller import BaseController from '../BaseController'; const { overlayContainer, flex1, w100, mb30, h100, justifyContentCenter, alignItemsCenter, mb20, px20, px10, textWhite, textCenter } = GlobalStyles; class Splash extends BaseController { state = { showTryButton: false, }; isConnected = false; /* * lifecycle method called when component mount */ componentDidMount() { NetInfo.isConnected.addEventListener('connectionChange', this._handleConnectionChange); // hide splash screen setTimeout(() => { SplashScreen.hide(); NetInfo.isConnected.fetch().done((isConnected) => { this._handleConnectionChange(isConnected); this.initializeApp(); }); }, 1000); } /** * Function to initialize Application */ async initializeApp() { if (this.isConnected) { let currentUser = await AsyncStorage.getItem(LocalStorageKeys.CURRENT_USER); let currentBusiness = await AsyncStorage.getItem(LocalStorageKeys.CURRENT_BUSINESS); if (currentUser) { await APIURLServiceSingleton.getInstance().saveUser(JSON.parse(currentUser)); await APIURLServiceSingleton.getInstance().saveCustmrBusiness(currentBusiness); await this.props.appInitialize(JSON.stringify(currentUser)); } else { await setRootScreen(AUTH, INITIAL_SCREEN); } } else { Toast.showWithGravity('Please check your internet connection and try again.', Toast.LONG, Toast.CENTER); } } /* * lifecycle method called when component unmount */ componentWillUnmount() { NetInfo.isConnected.removeEventListener('connectionChange', this._handleConnectionChange); } /** * Function to handle connection change */ _handleConnectionChange = (isConnected) => { if (isConnected) { this.isConnected = isConnected; } else { this.isConnected = isConnected; this.setState({ showTryButton: true }); } }; /** * Function called on try again */ async onTryAgain() { if (this.isConnected) { this.setState({ showTryButton: false }); } await this.initializeApp(); } // render method render() { const { showTryButton } = this.state; const { serverError } = this.props; return ( <View style={[flex1]}> <ImageView style={[overlayContainer, w100, h100]} resizeMode="cover" source={Images.splash} /> <View style={[flex1, justifyContentCenter, alignItemsCenter]}> <ImageView animation="fadeInDown" style={[mb30]} source={Images.appLogoLight} /> <Animatable.View animation="fadeInUp"> <Spinner color={Colors.white} /> </Animatable.View> {(showTryButton || serverError) && <View style={[mb20, px20]}> <Text style={[textWhite, textCenter, mb20, px10]}> {this.props.serverError ? APIResponseMessages.SERVER_TIMEOUT : APIResponseMessages.COULD_NOT_CONNECT_TO_THE_NETWORK} </Text> <Button large block onPress={this.onTryAgain.bind(this)}>{en.tryAgain}</Button> </View> } </View> </View> ); } } // map state to props const mapStateToProps = ({ AppInitializer, Common }) => { // const { showLoading } = Common; const { serverError } = AppInitializer; return { serverError }; }; export default connect(mapStateToProps, { appInitialize, loader })(Splash);
我的AppDelegate.m文件::
/** * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ #import "AppDelegate.h" #import <React/RCTBridge.h> #import <React/RCTBundleURLProvider.h> #import <React/RCTRootView.h> #import <ReactNativeNavigation/ReactNativeNavigation.h> #import "RNSplashScreen.h" @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { NSURL *jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil]; [ReactNativeNavigation bootstrap:jsCodeLocation launchOptions:launchOptions]; [RNSplashScreen show]; return YES; } @end
环境描述::
“ react-native-splash-screen”:“ 3.2.0”
xcode:11.2.1
问题描述::我正在开发react-native-ios应用,大多数情况下它在启动后卡住了。我在我的本机代码中创建了一个重复的初始屏幕。应用启动时,我是...
从崩溃消息中,您似乎忘记了为当前窗口设置根视图控制器。