React-native-firebase: 馃敟iOS firebase.notifications().getInitialNotification() on notification tap the app opens then exit unexpected

Created on 21 Jan 2019  路  10Comments  路  Source: invertase/react-native-firebase

Issue

iOS firebase.notifications().getInitialNotification() open when app when closed/killed but suddenly app is put to background. So, it's not launched as supposed to.. What's happening:

  • the app is closed
  • push notification appears
  • push notification is tapped
  • then, the app is launched
  • on the splash screen the app is put in background without user action

Project Files

iOS

ios/Podfile:

target 'viby' do
pod 'ExpoKit',
:git => "http://github.com/expo/expo.git",
:tag => "ios/2.10.1",
:subspecs => [
"Core"
],
:inhibit_warnings => true
pod 'EXAdsAdMob',
:path => "../node_modules/expo-ads-admob/ios"
pod 'EXAppAuth',
:path => "../node_modules/expo-app-auth/ios"
pod 'EXAppLoaderProvider',
:path => "../node_modules/expo-app-loader-provider/ios"
pod 'EXBackgroundFetch',
:path => "../node_modules/expo-background-fetch/ios"
pod 'EXBarCodeScanner',
:path => "../node_modules/expo-barcode-scanner/ios"
pod 'EXBarCodeScannerInterface',
:path => "../node_modules/expo-barcode-scanner-interface/ios"
pod 'EXCamera',
:path => "../node_modules/expo-camera/ios"
pod 'EXCameraInterface',
:path => "../node_modules/expo-camera-interface/ios"
pod 'EXConstants',
:path => "../node_modules/expo-constants/ios"
pod 'EXConstantsInterface',
:path => "../node_modules/expo-constants-interface/ios"
pod 'EXContacts',
:path => "../node_modules/expo-contacts/ios"
pod 'EXCore',
:path => "../node_modules/expo-core/ios"
pod 'EXErrors',
:path => "../node_modules/expo-errors/ios"
pod 'EXFaceDetectorInterface',
:path => "../node_modules/expo-face-detector-interface/ios"
pod 'EXFileSystem',
:path => "../node_modules/expo-file-system/ios"
pod 'EXFileSystemInterface',
:path => "../node_modules/expo-file-system-interface/ios"
pod 'EXFont',
:path => "../node_modules/expo-font/ios"
pod 'EXFontInterface',
:path => "../node_modules/expo-font-interface/ios"
pod 'EXGoogleSignIn',
:path => "../node_modules/expo-google-sign-in/ios"
pod 'EXGL',
:path => "../node_modules/expo-gl/ios"
pod 'EXGL-CPP',
:path => "../node_modules/expo-gl-cpp/cpp"
pod 'EXImageLoaderInterface',
:path => "../node_modules/expo-image-loader-interface/ios"
pod 'EXLocalAuthentication',
:path => "../node_modules/expo-local-authentication/ios"
pod 'EXLocalization',
:path => "../node_modules/expo-localization/ios"
pod 'EXLocation',
:path => "../node_modules/expo-location/ios"
pod 'EXMediaLibrary',
:path => "../node_modules/expo-media-library/ios"
pod 'EXPermissions',
:path => "../node_modules/expo-permissions/ios"
pod 'EXPermissionsInterface',
:path => "../node_modules/expo-permissions-interface/ios"
pod 'EXPrint',
:path => "../node_modules/expo-print/ios"
pod 'EXReactNativeAdapter',
:path => "../node_modules/expo-react-native-adapter/ios"
pod 'EXSegment',
:path => "../node_modules/expo-analytics-segment/ios"
pod 'EXSensors',
:path => "../node_modules/expo-sensors/ios"
pod 'EXSensorsInterface',
:path => "../node_modules/expo-sensors-interface/ios"
pod 'EXSMS',
:path => "../node_modules/expo-sms/ios"
pod 'EXTaskManager',
:path => "../node_modules/expo-task-manager/ios"
pod 'EXTaskManagerInterface',
:path => "../node_modules/expo-task-manager-interface/ios"

pod 'React',
:path => "../node_modules/react-native",
:inhibit_warnings => true,
:subspecs => [
"Core",
"ART",
"RCTActionSheet",
"RCTAnimation",
"RCTCameraRoll",
"RCTGeolocation",
"RCTImage",
"RCTNetwork",
"RCTText",
"RCTVibration",
"RCTWebSocket",
"DevSupport",
"CxxBridge"
]
pod 'yoga',
:path => "../node_modules/react-native/ReactCommon/yoga",
:inhibit_warnings => true
pod 'DoubleConversion',
:podspec => "../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec",
:inhibit_warnings => true
pod 'Folly',
:podspec => "../node_modules/react-native/third-party-podspecs/Folly.podspec",
:inhibit_warnings => true
pod 'glog',
:podspec => "../node_modules/react-native/third-party-podspecs/glog.podspec",
:inhibit_warnings => true

pod 'react-native-fetch-blob', :path => '../node_modules/react-native-fetch-blob'
pod 'RNFirebase', :path => '../node_modules/react-native-firebase/ios'

#pod 'GoogleAppMeasurement', '~> 5.4.0' #to fix this -> https://github.com/invertase/react-native-firebase/issues/1633#issuecomment-432801902

#pod 'Firebase'
pod 'Firebase/Core', '~> 5.15.0'
pod 'Firebase/RemoteConfig', '~> 5.15.0'
#pod 'Firebase/AdMob'
pod 'Firebase/Auth', '~> 5.15.0'
pod 'Firebase/Database', '~> 5.15.0'
pod 'Firebase/Functions', '~> 5.15.0'
pod 'Firebase/DynamicLinks', '~> 5.15.0'
pod 'Firebase/Firestore', '~> 5.15.0'
#pod 'Firebase/Invites'
pod 'Firebase/Messaging', '~> 5.15.0'
pod 'Firebase/Storage', '~> 5.15.0'
pod 'Firebase/Performance', '~> 5.15.0'

post_install do |installer|
installer.pods_project.main_group.tab_width = '2';
installer.pods_project.main_group.indent_width = '2';

installer.pod_targets.each do |target|

if target.pod_name == 'ExpoKit'
  target.native_target.build_configurations.each do |config|
    config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)']
    config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] << 'EX_DETACHED=1'

    # needed for GoogleMaps 2.x
    config.build_settings['FRAMEWORK_SEARCH_PATHS'] ||= []
    config.build_settings['FRAMEWORK_SEARCH_PATHS'] << '${PODS_ROOT}/GoogleMaps/Base/Frameworks'
    config.build_settings['FRAMEWORK_SEARCH_PATHS'] << '${PODS_ROOT}/GoogleMaps/Maps/Frameworks'
  end
end


if ['Amplitude-iOS','Analytics','AppAuth','Branch','CocoaLumberjack','FBSDKCoreKit','FBSDKLoginKit','FBSDKShareKit','GPUImage','JKBigInteger2'].include? target.pod_name
  target.native_target.build_configurations.each do |config|
    config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '10.0'
  end
end
# Can't specify this in the React podspec because we need
# to use those podspecs for detached projects which don't reference ExponentCPP.
if target.pod_name.start_with?('React')
  target.native_target.build_configurations.each do |config|
    config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '10.0'
    config.build_settings['HEADER_SEARCH_PATHS'] ||= ['$(inherited)']
  end
end
# Build React Native with RCT_DEV enabled and RCT_ENABLE_INSPECTOR and
# RCT_ENABLE_PACKAGER_CONNECTION disabled
next unless target.pod_name == 'React'
target.native_target.build_configurations.each do |config|
  config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)']
  config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] << 'RCT_DEV=1'
  config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] << 'RCT_ENABLE_INSPECTOR=0'
  config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] << 'ENABLE_PACKAGER_CONNECTION=0'
end

end

end
end
````

```ruby 2.5.1

#### `AppDelegate.m`:

```objc
// Copyright 2015-present 650 Industries. All rights reserved.

#import "AppDelegate.h"
#import <Firebase.h>
#import "RNFirebaseNotifications.h"
#import "RNFirebaseMessaging.h"


@implementation AppDelegate

// Put your app delegate methods here. Remember to also call methods from EXStandaloneAppDelegate superclass
// in order to keep Expo working. See example below.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  [FIRApp configure];
  [RNFirebaseNotifications configure];
  return [super application:application didFinishLaunchingWithOptions:launchOptions];
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(nonnull NSDictionary *)userInfo
fetchCompletionHandler:(nonnull void (^)(UIBackgroundFetchResult))completionHandler{
    [[RNFirebaseNotifications instance] didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];
}

- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings {
    [[RNFirebaseMessaging instance] didRegisterUserNotificationSettings:notificationSettings];
}

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
    [[RNFirebaseNotifications instance] didReceiveLocalNotification:notification];
}

@end

Environment

  • 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

  • If known, the version of the platform are you experiencing the issue on:

    • ADD_SOMETHING_HERE e.g. iOS 10 or Android API 28

  • Operating System:

    • [ ] MacOS, version: macOS 10.14

    • [ ] Windows, version: N/A

    • [ ] Other, please specify: N/A

  • Build Tools:

    • Xcode 10 e.g. Xcode 10, Android Studio 3.2

  • **React Native version: 0.57.1

    • ADD_SOMETHING_HERE

  • **React Native Firebase library version: 5.15.0

    • ADD_SOMETHING_HERE

  • Firebase module(s) you're using that has the issue:

    • [x] N/A

    • [ ] Authentication

    • [ ] Analytics

    • [ ] Cloud Firestore

    • [ ] Cloud Messaging (FCM)

    • [ ] Crashlytics

    • [ ] Dynamic Links

    • [ ] Functions Callable

    • [ ] Invites

    • [ ] Instance ID

    • [x] Notifications

    • [ ] Performance Monitoring

    • [ ] Realtime Database

    • [ ] Remote Config

    • [ ] Storage

  • Are you using TypeScript?

    • [ ] No

    • [ ] Yes, version: N/A

  • Are you using Expo, e.g. ExpoKit?

    • [ ] No

    • [ ] Yes, I've _not_ ejected

    • [x] Yes, but I have ejected to ExpoKit

    • [ ] Yes, but I have ejected to vanilla React Native

    • Expo version: 32.0.0

expo diagnostics
Expo CLI 2.6.14 environment info: System: OS: macOS 10.14 Shell: 3.2.57 - /bin/bash Binaries: Node: 9.8.0 - /usr/local/bin/node Yarn: 1.5.1 - /usr/local/bin/yarn npm: 5.6.0 - /usr/local/bin/npm Watchman: 4.9.0 - /usr/local/bin/watchman IDEs: Android Studio: 3.0 AI-171.4443003 Xcode: 10.1/10B61 - /usr/bin/xcodebuild npmPackages: expo: ^32.0.0 => 32.0.0 react: 16.5.0 => 16.5.0 react-native: https://github.com/expo/react-native/archive/sdk-32.0.0.tar.gz => 0.57.1 react-navigation: ^3.0.9 => 3.0.9 npmGlobalPackages: expo-cli: 2.6.14




Think react-native-firebase is great? Please consider supporting the project with any of the below:

Most helpful comment

We can close this one, I guess. It was an expokit issue https://github.com/expo/expo/pull/3431/files

All 10 comments

Do you have any native logs? The app going to the background sounds like a crash

@Salakar the app still running when it gets in background.. I will have a look the log

@Salakar no logs..

@Salakar does have any additional config, including AppDelegate.m, to start the app when closed/killed?!?

Is there a special case where it happens in dev mode?!? I mean.. expo loads the bundle javascript when the app starts..

@salakar does it work with expo in not published app? I mean, it's local environment everytime the app loads it bundle the javascript. I'll test with published app it maybe works.

I guess there's a missing piece of code in my AppDelegate.m . Even removing all firebase code that handles the notification the app still exiting..

We are facing the same issue, no solution yet on our side. I also digged into AppDelegate.m looing for a missing onPendingNotification or something alike.

We can close this one, I guess. It was an expokit issue https://github.com/expo/expo/pull/3431/files

@coulix it worked for me. I edited the EXKernel.m and worked. Since it's in a pull-request I'll close it..

Was this page helpful?
0 / 5 - 0 ratings

Related issues

NordlingDev picture NordlingDev  路  3Comments

alizahid picture alizahid  路  3Comments

joecaraccio picture joecaraccio  路  3Comments

ODelibalta picture ODelibalta  路  3Comments

dgruseck picture dgruseck  路  3Comments