AppDelegate.m
这工作正常(当应用程序进入后台时显示启动)
- (void)applicationDidEnterBackground:(UIApplication *)application
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"NativeScreens" bundle:nil];
SplashVC *SplashViewController=[storyboard instantiateViewControllerWithIdentifier:@"SplashVC"];
[self.window.rootViewController presentViewController:SplashViewController animated:NO completion:NULL];
}
但现在我需要从 react-native 调用它。
我创建了一个具有相同功能的方法:
RCT_EXPORT_METHOD(showCustomNativeSplashScreen)
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"NativeScreens" bundle:nil];
SplashVC *SplashViewController=[storyboard instantiateViewControllerWithIdentifier:@"SplashVC"];
[self.window.rootViewController presentViewController:SplashViewController animated:NO completion:NULL];
}
它在 RN 中可用,(我从 console.log 中看到它)但是当我调用它时 - 没有任何反应。
import { NativeModules } from 'react-native';
...
console.log(NativeModules.AppDelegate); // Object{showCustomNativeSplashScreen: function}
NativeModules.AppDelegate.showCustomNativeSplashScreen(); // nothing :(
我究竟做错了什么?