react-native-splash-screen 在 IOS 中自动隐藏。 但在 android 中工作很好。
我按照以下步骤操作:-
1)npm 我反应本机启动画面--保存 2)cd ios,运行 pod install 3)更新了AppDelegate.m
#import "RNSplashScreen.h" // here
....
[RNSplashScreen show]; // here
....
4)通过LaunchScreen.storyboard自定义我的启动屏幕
5)APP.JS
import SplashScreen from 'react-native-splash-screen'
componentDidMount() {
setTimeout(async() => {
SplashScreen.hide();
},3000);
}
但是启动画面在 IOS 中不会等待 3 秒,但在 Android 中运行良好 另外,如果我评论“SplashScreen.hide();”另外,S-Screen 在 IOS 中会自动隐藏。
我建议你使用这个库https://github.com/zoontek/react-native-bootsplash它支持React Native的最新版本并且在你描述的情况下工作完美
我遇到了同样的问题,并通过为 didFinishLaunchingWithOptions 函数的返回值分配一个值并在 return 语句中返回该值来修复它。
旧代码:
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.moduleName = @"MyApp";
self.initialProps = @{};
return [super application:application didFinishLaunchingWithOptions:launchOptions];
}
新代码:
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.moduleName = @"MyApp";
self.initialProps = @{};
bool didFinish=[super application:application didFinishLaunchingWithOptions:launchOptions]; // this is important
[RNSplashScreen show]; // here
return didFinish; // this is important
}
我对 ObjectiveC 不够精通,无法解释为什么解析器会这样工作,但这对我和其他人来说是有效的,如这篇 github 帖子中所指定的:
https://github.com/crazycodeboy/react-native-splash-screen/issues/598