Ios React Native-通过AppDelegate方法显示ViewController
AppDelegate.mIos React Native-通过AppDelegate方法显示ViewController,ios,objective-c,react-native,Ios,Objective C,React Native,AppDelegate.m 这是正确的(当应用程序进入后台时显示飞溅) 但是现在我需要从react本地调用它。 我创建了一个具有相同功能的方法: RCT_EXPORT_METHOD(showCustomNativeSplashScreen) { UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"NativeScreens" bundle:nil]; SplashVC *SplashViewController=[s
这是正确的(当应用程序进入后台时显示飞溅) 但是现在我需要从react本地调用它。
我创建了一个具有相同功能的方法:
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 :(
我做错了什么?必须找到上层控制器
import { NativeModules } from 'react-native';
...
console.log(NativeModules.AppDelegate); // Object{showCustomNativeSplashScreen: function}
NativeModules.AppDelegate.showCustomNativeSplashScreen(); // nothing :(
- (UIViewController *)topViewController{
return [self topViewController:[UIApplication sharedApplication].keyWindow.rootViewController];
}
- (UIViewController *)topViewController:(UIViewController *)rootViewController
{
if (rootViewController.presentedViewController == nil) {
return rootViewController;
}
if ([rootViewController.presentedViewController isMemberOfClass:[UINavigationController class]]) {
UINavigationController *navigationController = (UINavigationController *)rootViewController.presentedViewController;
UIViewController *lastViewController = [[navigationController viewControllers] lastObject];
return [self topViewController:lastViewController];
}
UIViewController *presentedViewController = (UIViewController *)rootViewController.presentedViewController;
return [self topViewController:presentedViewController];
}
RCT_EXPORT_METHOD(showCustomNativeSplashScreen)
{
self.lastTopVC = [self topViewController];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"NativeScreens" bundle:nil];
SplashVC *SplashViewController=[storyboard instantiateViewControllerWithIdentifier:@"SplashVC"];
[self.lastTopVC presentViewController:SplashViewController animated:NO completion:NULL];
}