invertase / react-native-firebase

🔥 A well-tested feature-rich modular Firebase implementation for React Native. Supports both iOS & Android platforms for all Firebase services.
https://rnfirebase.io
Other
11.7k stars 2.22k forks source link

[🐛] iOS stuck launch screen when receive message in quit app state #6589

Closed thanhchuongbmd closed 2 years ago

thanhchuongbmd commented 2 years ago

Issue


Project Files

Javascript

Click To Expand

#### `package.json`: ```json "@react-native-firebase/app": "14.3.3", "@react-native-firebase/messaging": "14.3.3", "react-native": "0.63.4", "react": "16.13.1", "expo": "^41.0.0" ``` #### `index.js`: ```js import React from "react"; import "react-native-gesture-handler"; import { registerRootComponent } from "expo"; import messaging from "@react-native-firebase/messaging"; import App from "./App"; import { Platform } from "react-native"; // Register background handler messaging().setBackgroundMessageHandler(async ()=>{ console.log('setBackgroundMessageHandler event'); }); function HeadlessCheck({ isHeadless }) { console.log('HeadlessCheck:', isHeadless) if (isHeadless) { return null; } return ; } registerRootComponent(HeadlessCheck); ```

iOS

Click To Expand

#### `ios/Podfile`: - [ ] I'm not using Pods - [x] I'm using Pods and my Podfile looks like: ```ruby require_relative '../node_modules/react-native/scripts/react_native_pods' require_relative '../node_modules/react-native-unimodules/cocoapods.rb' require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules' platform :ios, '11.0' target 'TikaExpert' do use_unimodules! config = use_native_modules! use_react_native!(:path => config["reactNativePath"]) pod 'react-native-maps', :path => '../node_modules/react-native-maps' pod 'react-native-google-maps', :path => '../node_modules/react-native-maps' pod 'react-native-image-crop-tools', :path => '../node_modules/react-native-image-crop-tools' # Uncomment the code below to enable Flipper. # # You should not install Flipper in CI environments when creating release # builds, this will lead to significantly slower build times. # # Note that if you have use_frameworks! enabled, Flipper will not work. # # use_flipper!({ 'Flipper-Folly' => '2.3.0' }) # post_install do |installer| # flipper_post_install(installer) # end #fix for xcode 14 post_install do |installer| installer.pods_project.targets.each do |target| target.build_configurations.each do |config| config.build_settings['CODE_SIGN_IDENTITY'] = '' end end end end ``` #### `AppDelegate.m`: ```objc #import "AppDelegate.h" #import #import #import #import "RNSplashScreen.h" // here #import "TikaExpert-Swift.h" // here, change project name to yours #import "RNFBMessagingModule.h" #import #import #import #import #import #import #import #import "GoogleMaps/GoogleMaps.h" #import // <- Add This Import #import #import #import "RNCallKeep.h" #import @import Firebase; #if defined(FB_SONARKIT_ENABLED) && __has_include() #import #import #import #import #import #import 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 () @property (nonatomic, strong) UMModuleRegistryAdapter *moduleRegistryAdapter; @property (nonatomic, strong) NSDictionary *launchOptions; @end @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { #if defined(FB_SONARKIT_ENABLED) && __has_include() 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]; [CallAppInterface setHomeViewController: controller]; #endif [super application:application didFinishLaunchingWithOptions:launchOptions]; #ifdef DEBUG Dynamic *t = [Dynamic new]; UIView *animationView = [t createAnimationViewWithRootView:self.window.rootViewController.view lottieName:@"progress"]; // change lottieName to your lottie files name // register LottieSplashScreen to RNSplashScreen [RNSplashScreen showLottieSplash:animationView inRootView:self.window.rootViewController.view]; // play [t playWithAnimationView:animationView]; // If you want the animation layout to be forced to remove when hide is called, use this code [RNSplashScreen setAnimationFinished:true]; /* here */ #endif // Define UNUserNotificationCenter UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; center.delegate = self; [FIRApp configure]; [GMSServices provideAPIKey:@"xxx"]; [[FBSDKApplicationDelegate sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions]; [RNCallKeep setup:@{ @"appName": @"Tika Expert", @"maximumCallGroups": @3, @"maximumCallsPerCallGroup": @1, @"supportsVideo": @YES, }]; return YES; } -(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler { completionHandler(UNNotificationPresentationOptionSound | UNNotificationPresentationOptionAlert | UNNotificationPresentationOptionBadge); } - (RCTBridge *)initializeReactNativeApp { NSDictionary *appProperties = [RNFBMessagingModule addCustomPropsToUserProps:nil withLaunchOptions:self.launchOptions]; RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:self.launchOptions]; RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge moduleName:@"main" initialProperties:appProperties]; rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1]; UIViewController *rootViewController = [UIViewController new]; rootViewController.view = rootView; self.window.rootViewController = rootViewController; [self.window makeKeyAndVisible]; [CallAppInterface setHomeViewController: rootViewController]; return bridge; } - (NSArray> *)extraModulesForBridge:(RCTBridge *)bridge { NSArray> *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]; Dynamic *t = [Dynamic new]; UIView *animationView = [t createAnimationViewWithRootView:self.window.rootViewController.view lottieName:@"progress"]; // change lottieName to your lottie files name // register LottieSplashScreen to RNSplashScreen [RNSplashScreen showLottieSplash:animationView inRootView:self.window.rootViewController.view]; // play [t playWithAnimationView:animationView]; // If you want the animation layout to be forced to remove when hide is called, use this code [RNSplashScreen setAnimationFinished:true]; /* here */ } // Required for the register event. - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { [RNCPushNotificationIOS didRegisterForRemoteNotificationsWithDeviceToken:deviceToken]; } // Required for the notification event. You must call the completion handler after handling the remote notification. - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { [RNCPushNotificationIOS didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler]; } // Required for the registrationError event. - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error { [RNCPushNotificationIOS didFailToRegisterForRemoteNotificationsWithError:error]; } // Required for localNotification event - (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler { [RNCPushNotificationIOS didReceiveNotificationResponse:response]; } - (BOOL)application:(UIApplication *)application openURL:(nonnull NSURL *)url options:(nonnull NSDictionary *)options { if ([[FBSDKApplicationDelegate sharedInstance] application:application openURL:url options:options]) { return YES; } if ([RNGoogleSignin application:application openURL:url options:options]) { return YES; } if ([RCTLinkingManager application:application openURL:url options:options]) { return YES; } return NO; } - (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void(^)(NSArray * __nullable restorableObjects))restorationHandler { return [RNCallKeep application:application continueUserActivity:userActivity restorationHandler:restorationHandler]; } @end ```


Environment

Click To Expand

**`react-native info` output:** ``` System: OS: macOS 12.6 CPU: (8) x64 Intel(R) Core(TM) i7-7920HQ CPU @ 3.10GHz Memory: 67.93 MB / 16.00 GB Shell: 5.8.1 - /bin/zsh Binaries: Node: 16.13.1 - /usr/local/bin/node Yarn: 1.22.17 - /usr/local/bin/yarn npm: 8.1.2 - /usr/local/bin/npm Watchman: Not Found Managers: CocoaPods: 1.11.3 - /usr/local/bin/pod SDKs: iOS SDK: Platforms: DriverKit 21.4, iOS 16.0, macOS 12.3, tvOS 16.0, watchOS 9.0 Android SDK: Not Found IDEs: Android Studio: 2021.1 AI-211.7628.21.2111.8193401 Xcode: 14.0/14A309 - /usr/bin/xcodebuild Languages: Java: javac 18 - /usr/bin/javac Python: 3.9.12 - /Users/chuongdev/miniconda3/bin/python npmPackages: @react-native-community/cli: ^9.1.3 => 9.1.3 react: 16.13.1 => 16.13.1 react-native: 0.63.4 => 0.63.4 react-native-macos: Not Found npmGlobalPackages: *react-native*: Not Found ``` - **Platform that you're experiencing the issue on**: - [x] iOS - [ ] Android - [ ] **iOS** but have not tested behavior on Android - [ ] **Android** but have not tested behavior on iOS - [ ] Both


mikehardy commented 2 years ago

Can you update to current versions of react-native and react-native-firebase and try again? I can't diagnose on old versions. You can create an MCVE (https://stackoverflow.com/help/minimal-reproducible-example) using this if desired https://github.com/mikehardy/rnfbdemo/blob/main/make-demo.sh

thanhchuongbmd commented 2 years ago

Can you update to current versions of react-native and react-native-firebase and try again? I can't diagnose on old versions. You can create an MCVE (https://stackoverflow.com/help/minimal-reproducible-example) using this if desired https://github.com/mikehardy/rnfbdemo/blob/main/make-demo.sh

Thank you, I'll check!

thanhchuongbmd commented 2 years ago

Can you update to current versions of react-native and react-native-firebase and try again? I can't diagnose on old versions. You can create an MCVE (https://stackoverflow.com/help/minimal-reproducible-example) using this if desired https://github.com/mikehardy/rnfbdemo/blob/main/make-demo.sh

Thanks for your help!