在启动屏幕加载iOS之前对本机黑屏做出反应
我试图通过大量的Stackoverflow问题和Github问题来解决此问题,但都无济于事,因此我请求帮助。 我已经创建了一个弹出(来自expo)的react本机应用程序。我已经手动和通过世博会的自动启动屏幕安装生成了启动屏幕。SplashScreen通过XCode正确链接(通过选择SplashScreen.storyboard文件作为启动屏幕)。 在iOS上通过TestFlight打开应用程序时,第一个加载的屏幕是一个黑屏。大约半秒钟后,我的SplashScreen显示出来。我不知道为什么会发生这种情况,我尝试过在删除应用程序后重新安装它,在归档之前清理我的构建文件夹,删除情节提要文件并重新实现它,但似乎没有任何效果。我将在下面发布我的AppDelegate文件,以防出现问题。如有任何建议,我们将不胜感激在启动屏幕加载iOS之前对本机黑屏做出反应,ios,swift,react-native,expo,splash-screen,Ios,Swift,React Native,Expo,Splash Screen,我试图通过大量的Stackoverflow问题和Github问题来解决此问题,但都无济于事,因此我请求帮助。 我已经创建了一个弹出(来自expo)的react本机应用程序。我已经手动和通过世博会的自动启动屏幕安装生成了启动屏幕。SplashScreen通过XCode正确链接(通过选择SplashScreen.storyboard文件作为启动屏幕)。 在iOS上通过TestFlight打开应用程序时,第一个加载的屏幕是一个黑屏。大约半秒钟后,我的SplashScreen显示出来。我不知道为什么会发
#import "AppDelegate.h"
#import <React/RCTBridge.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import <UMCore/UMModuleRegistry.h>
#import <UMReactNativeAdapter/UMNativeModulesProxy.h>
#import <UMReactNativeAdapter/UMModuleRegistryAdapter.h>
#import <EXSplashScreen/EXSplashScreenService.h>
#import <UMCore/UMModuleRegistryProvider.h>
#import <EXScreenOrientation/EXScreenOrientationViewController.h>
#ifdef FB_SONARKIT_ENABLED
#import <FlipperKit/FlipperClient.h>
#import <FlipperKitLayoutPlugin/FlipperKitLayoutPlugin.h>
#import <FlipperKitUserDefaultsPlugin/FKUserDefaultsPlugin.h>
#import <FlipperKitNetworkPlugin/FlipperKitNetworkPlugin.h>
#import <SKIOSNetworkPlugin/SKIOSNetworkAdapter.h>
#import <FlipperKitReactPlugin/FlipperKitReactPlugin.h>
static void InitializeFlipper(UIApplication *application) {
FlipperClient *client = [FlipperClient sharedClient];
SKDescriptorMapper *layoutDescriptorMapper = [[SKDescriptorMapper alloc] initWithDefaults];
[client addPlugin:[[FlipperKitLayoutPlugin alloc] initWithRootNode:application withDescriptorMapper:layoutDescriptorMapper]];
[client addPlugin:[[FKUserDefaultsPlugin alloc] initWithSuiteName:nil]];
[client addPlugin:[FlipperKitReactPlugin new]];
[client addPlugin:[[FlipperKitNetworkPlugin alloc] initWithNetworkAdapter:[SKIOSNetworkAdapter new]]];
[client start];
}
#endif
@interface AppDelegate () <RCTBridgeDelegate>
@property (nonatomic, strong) UMModuleRegistryAdapter *moduleRegistryAdapter;
@property (nonatomic, strong) NSDictionary *launchOptions;
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
#ifdef FB_SONARKIT_ENABLED
InitializeFlipper(application);
#endif
self.moduleRegistryAdapter = [[UMModuleRegistryAdapter alloc] initWithModuleRegistryProvider:[[UMModuleRegistryProvider alloc] init]];
self.launchOptions = launchOptions;
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
#ifdef DEBUG
[self initializeReactNativeApp];
#else
EXUpdatesAppController *controller = [EXUpdatesAppController sharedInstance];
controller.delegate = self;
[controller startAndShowLaunchScreen:self.window];
#endif
[super application:application didFinishLaunchingWithOptions:launchOptions];
return YES;
}
- (RCTBridge *)initializeReactNativeApp
{
RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:self.launchOptions];
RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge moduleName:@"main" initialProperties:nil];
rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
UIViewController *rootViewController = [[EXScreenOrientationViewController alloc] init];
rootViewController.view = rootView;
self.window.rootViewController = rootViewController;
[self.window makeKeyAndVisible];
return bridge;
}
- (NSArray<id<RCTBridgeModule>> *)extraModulesForBridge:(RCTBridge *)bridge
{
NSArray<id<RCTBridgeModule>> *extraModules = [_moduleRegistryAdapter extraModulesForBridge:bridge];
// If you'd like to export some custom RCTBridgeModules that are not Expo modules, add them here!
return extraModules;
}
- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge {
#ifdef DEBUG
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
#else
return [[EXUpdatesAppController sharedInstance] launchAssetUrl];
#endif
}
- (void)appController:(EXUpdatesAppController *)appController didStartWithSuccess:(BOOL)success {
appController.bridge = [self initializeReactNativeApp];
EXSplashScreenService *splashScreenService = (EXSplashScreenService *)[UMModuleRegistryProvider getSingletonModuleForClass:[EXSplashScreenService class]];
[splashScreenService showSplashScreenFor:self.window.rootViewController];
}
@end
#导入“AppDelegate.h”
#进口
#进口
#进口
#进口
#进口
#进口
#进口
#进口
#进口
#ifdef FB_声纳套件已启用
#进口
#进口
#进口
#进口
#进口
#进口
静态无效初始化EFLIPPER(UIApplication*应用程序){
FlipperClient*客户端=[FlipperClient sharedClient];
SKDescriptorMapper*layoutDescriptorMapper=[[SKDescriptorMapper alloc]initWithDefaults];
[客户端添加插件:[[FlipperKitLayoutPlugin alloc]initWithRootNode:应用程序withDescriptorMapper:layoutDescriptorMapper];
[客户端添加插件:[[FKUserDefaultsPlugin alloc]initWithSuiteName:nil];
[客户端添加插件:[FlipperKitReactPlugin new]];
[客户端添加插件:[[FlipperKitNetworkPlugin alloc]initWithNetworkAdapter:[SKIOSNetworkAdapter new]];
[客户端启动];
}
#恩迪夫
@接口AppDelegate()
@属性(非原子,强)UMModuleRegistryAdapter*moduleRegistryAdapter;
@属性(非原子,强)NSDictionary*启动选项;
@结束
@实现AppDelegate
-(BOOL)应用程序:(UIApplication*)应用程序使用选项完成启动:(NSDictionary*)启动选项
{
#ifdef FB_声纳套件已启用
初始化Lipper(应用程序);
#恩迪夫
self.moduleRegistryAdapter=[[UMModuleRegistryAdapter alloc]initWithModuleRegistryProvider:[[UMModuleRegistryProvider alloc]init];
self.launchOptions=启动选项;
self.window=[[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
#ifdef调试
[自初始化反应PP];
#否则
EXUpdatesAppController*控制器=[EXUpdatesAppController sharedInstance];
controller.delegate=self;
[控制器启动和显示启动屏幕:self.window];
#恩迪夫
[超级应用程序:应用程序使用选项完成启动:启动选项];
返回YES;
}
-(RCTBridge*)初始化ActionalApp
{
RCTBridge*bridge=[[RCTBridge alloc]initWithDelegate:self-launchOptions:self.launchOptions];
RCTRootView*rootView=[[RCTRootView alloc]initWithBridge:bridge moduleName:@“main”initialProperties:nil];
rootView.backgroundColor=[[UIColor alloc]initWithRed:1.0f绿色:1.0f蓝色:1.0f alpha:1];
self.window=[[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
UIViewController*rootViewController=[[ExScreenOrientionViewController alloc]init];
rootViewController.view=rootView;
self.window.rootViewController=rootViewController;
[self.window makeKeyAndVisible];
返回桥;
}
-(NSArray*)桥接器的额外模块:(RCTBridge*)桥接器
{
NSArray*extraModules=[[u moduleRegistryAdapter extraModulesForBridge:bridge];
//如果您想导出一些非Expo模块的自定义RCTBridgeModule,请在此处添加它们!
返回模块;
}
-(NSURL*)源URLFORBRIDGE:(RCTBridge*)桥{
#ifdef调试
返回[[RCTBundleURLProvider sharedSettings]JSBundleUrlForbundlerRoot:@“索引”后备资源:nil];
#否则
返回[[EXUpdatesAppController sharedInstance]启动组件];
#恩迪夫
}
-(void)appController:(EXUpdatesAppController*)appController didStartWithSuccess:(BOOL)success{
appController.bridge=[self initializeReactNativeApp];
EXSplashScreenService*splashScreenService=(EXSplashScreenService*)[UmoduleRegistryProvider getSingletonModuleForClass:[EXSplashScreenService类]];
[splashScreenService showSplashScreenFor:self.window.rootViewController];
}
@结束
#导入
#进口
#进口
#进口
#进口
@接口AppDelegate:UMAppDelegateWrapper
@结束
在XCode 12.0和iOS 14上尝试以下步骤
如果没有,请创建LaunchScreen.storyboard
设计视图,类似这样的东西
并将ViewController的情节提要id更新为LaunchViewController
使用以下代码更新AppDelegate.m的选项didFinishLaunchingWithOptions
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
....
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"LaunchScreen" bundle:[NSBundle mainBundle]];
UIViewController *launchScrenViewController = [storyboard instantiateViewControllerWithIdentifier:@"LaunchViewController"];
launchScrenViewController.view.frame = self.window.bounds;
rootView.loadingView = launchScrenViewController.view;
..
return YES;
}
选择LaunchScreen作为主界面,并在Xcode中选择LaunchScreen。这里有一个例子
这将解决您的问题。谢谢您的帮助。我会试试看。SplashScreen.storyboard(我已经创建并链接了)和LaunchScreen之间有什么区别吗?我认为这无关紧要。我的RN项目中已经有LaunchScreen.storyboard,它是由
react native init创建的
解决了吗?我面临着类似的问题。应用程序的第一个屏幕是react native屏幕,所有其他屏幕都是native屏幕。加载RN屏幕时,加载需要时间。而在这期间,它会显示2-3秒的黑屏。似乎是因为加载了js包,有什么办法解决这个问题吗?
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
....
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"LaunchScreen" bundle:[NSBundle mainBundle]];
UIViewController *launchScrenViewController = [storyboard instantiateViewControllerWithIdentifier:@"LaunchViewController"];
launchScrenViewController.view.frame = self.window.bounds;
rootView.loadingView = launchScrenViewController.view;
..
return YES;
}