Hey there,
back in SDK40 I patched expo-splash-screen to hide the app’s content from the AppSwitcher when the app goes to background. This worked fine until I upgraded to SDK41. Now I’m getting the following error:
NSInvalidArgumentException (RNSScreen)
-[EXSplashScreenService forceShowSplashScreenFor:]: unrecognized selector sent to instance 0x600000d24310
The error is thrown in applicationDidEnterBackground
, it doesn’t even enter the forceShowSplashScreenFor
function. I’m not an iOS developer - any idea what I’m missing here?
diff --git a/ios/MyApp/AppDelegate.m b/ios/MyApp/AppDelegate.m
index 5a081f14..c5662908 100644
--- a/ios/MyApp/AppDelegate.m
+++ b/ios/MyApp/AppDelegate.m
@@ -96,7 +96,7 @@ - (RCTBridge *)initializeReactNativeApp
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]
+ UIViewController *rootViewController = [[EXScreenOrientationViewController alloc]
initWithDefaultScreenOrientationMask:UIInterfaceOrientationMaskPortrait];
rootViewController.view = rootView;
self.window.rootViewController = rootViewController;
@@ -126,4 +126,16 @@ - (void)appController:(EXUpdatesAppController *)appController didStartWithSucces
[splashScreenService showSplashScreenFor:self.window.rootViewController];
}
+- (void)applicationWillEnterForeground:(UIApplication *)application {
+ EXSplashScreenService *splashScreenService = (EXSplashScreenService *)[UMModuleRegistryProvider getSingletonModuleForClass:[EXSplashScreenService class]];
+ [splashScreenService hideSplashScreenFor:self.window.rootViewController
+ successCallback:^(BOOL hasEffect){ /* IGNORE */ }
+ failureCallback:^(NSString *message){ /* IGNORE */ }];
+}
+
+- (void)applicationDidEnterBackground:(UIApplication *)application {
+ EXSplashScreenService *splashScreenService = (EXSplashScreenService *)[UMModuleRegistryProvider getSingletonModuleForClass:[EXSplashScreenService class]];
+ [splashScreenService forceShowSplashScreenFor:self.window.rootViewController];
+}
+
@end
and the patch for expo-splash-screen to add the forceShowSplashScreenFor
function:
diff --git a/node_modules/expo-splash-screen/ios/EXSplashScreen/EXSplashScreenService.h b/node_modules/expo-splash-screen/ios/EXSplashScreen/EXSplashScreenService.h
index d4e6372..8555c0a 100644
--- a/node_modules/expo-splash-screen/ios/EXSplashScreen/EXSplashScreenService.h
+++ b/node_modules/expo-splash-screen/ios/EXSplashScreen/EXSplashScreenService.h
@@ -15,6 +15,12 @@ NS_ASSUME_NONNULL_BEGIN
*/
@protocol EXSplashScreenService <NSObject>
+/**
+ * patched method to force re-showing of the splash screen
+ */
+- (void)forceShowSplashScreenFor:(UIViewController *)viewController;
+
+
/**
* Overloaded method. See main method below.
*/
diff --git a/node_modules/expo-splash-screen/ios/EXSplashScreen/EXSplashScreenService.m b/node_modules/expo-splash-screen/ios/EXSplashScreen/EXSplashScreenService.m
index 72ababa..c56a888 100644
--- a/node_modules/expo-splash-screen/ios/EXSplashScreen/EXSplashScreenService.m
+++ b/node_modules/expo-splash-screen/ios/EXSplashScreen/EXSplashScreenService.m
@@ -22,6 +22,12 @@ - (instancetype)init
return self;
}
+- (void)forceShowSplashScreenFor:(UIViewController *)viewController
+{
+ return [[self.splashScreenControllers objectForKey:viewController] showWithCallback:^{}
+ failureCallback:^(NSString *message){ UMLogWarn(@"%@", message); }];
+}
+
- (void)showSplashScreenFor:(UIViewController *)viewController
{
id<EXSplashScreenViewProvider> splashScreenViewProvider = [EXSplashScreenViewNativeProvider new];