React-native-firebase: onNotification, onMessage and onNotificationOpened does not work in background

Created on 15 Oct 2018  路  6Comments  路  Source: invertase/react-native-firebase

Issue

I created a repo with my code.
https://github.com/guitar9/RNFirebaseTest/
I only removed google-services.json because of privacy.

I did these steps:
https://rnfirebase.io/docs/v5.x.x/messaging/receiving-messages
https://rnfirebase.io/docs/v5.x.x/messaging/android

When my App is in Background onNotification, onMessage in App.js does not fire.
When i click on the Notification onNoticationOpened does not fire.
For test i create a Toast when the event is fired.
I send the message through firebase console.
Can somebody help me?

Environment

  1. Application Target Platform:

Android

  1. Development Operating System:

Linux

  1. React Native version:

0.57.1

  1. React Native Firebase Version:

5.0.0

  1. Firebase Module:

messaging, notfication

  1. Are you using typescript?
    no
Notifications

Most helpful comment

Use getInitialNotification.

eg:

firebase.notifications().getInitialNotification().then((notification) => {
  // Process your message as required
});

All 6 comments

Somebody can help me or somebody has a working example and can paste code here?

This gives me logcat: (When i send a push notifivation and click on the notification)

10-17 09:43:17.601 30382-31441/com.ktappworks.firebasetest W/FirebaseMessaging: Missing Default Notification Channel metadata in AndroidManifest. Default value will be used.
10-17 09:43:17.608 30382-31441/com.ktappworks.firebasetest D/Notification: allPendingIntents
10-17 09:43:28.317 30382-30382/com.ktappworks.firebasetest D/ReactNative: ReactInstanceManager.detachViewFromInstance()
10-17 09:43:28.367 30382-30382/com.ktappworks.firebasetest D/ViewRootImpl@8bb7827[MainActivity]: dispatchDetachedFromWindow
10-17 09:43:28.367 30382-30382/com.ktappworks.firebasetest D/InputEventReceiver: channel '9f863a2 com.ktappworks.firebasetest/com.ktappworks.firebasetest.MainActivity (client)' ~ Disposing input event receiver.
    channel '9f863a2 com.ktappworks.firebasetest/com.ktappworks.firebasetest.MainActivity (client)' ~NativeInputEventReceiver.
10-17 09:43:28.394 30382-30382/com.ktappworks.firebasetest D/ReactNative: ReactInstanceManager.attachRootViewToInstance()
10-17 09:43:28.397 30382-31033/com.ktappworks.firebasetest I/ReactNativeJS: Running application "firebasetest" with appParams: {"rootTag":21}. __DEV__ === true, development-level warning are ON, performance optimizations are OFF
10-17 09:43:28.414 30382-30382/com.ktappworks.firebasetest I/FirebasePerformance: Session ID - 57c84416312c4dd0bc63f516cd4be947
10-17 09:43:28.437 30382-30382/com.ktappworks.firebasetest D/ViewRootImpl@949bb67[MainActivity]: setView = DecorView@4285d14[MainActivity] TM=true MM=false
10-17 09:43:28.461 30382-30382/com.ktappworks.firebasetest D/SensorManager: registerListener :: 1, K6DS3TR Acceleration Sensor, 66667, 0,  
10-17 09:43:28.463 30382-30382/com.ktappworks.firebasetest D/ViewRootImpl@949bb67[MainActivity]: dispatchAttachedToWindow
10-17 09:43:28.486 30382-30382/com.ktappworks.firebasetest V/Surface: sf_framedrop debug : 0x4f4c, game : false, logging : 0
10-17 09:43:28.487 30382-30382/com.ktappworks.firebasetest D/ViewRootImpl@949bb67[MainActivity]: Relayout returned: old=[0,0][0,0] new=[0,0][1080,1920] result=0x7 surface={valid=true 3378739200} changed=true
10-17 09:43:28.495 30382-30572/com.ktappworks.firebasetest D/mali_winsys: EGLint new_window_surface(egl_winsys_display *, void *, EGLSurface, EGLConfig, egl_winsys_surface **, egl_color_buffer_format *, EGLBoolean) returns 0x3000,  [1080x1920]-format:1
10-17 09:43:28.495 30382-30572/com.ktappworks.firebasetest D/OpenGLRenderer: eglCreateWindowSurface = 0xdb9dbb40
10-17 09:43:28.515 30382-30382/com.ktappworks.firebasetest D/ViewRootImpl@949bb67[MainActivity]: MSG_RESIZED_REPORT: frame=Rect(0, 0 - 1080, 1920) ci=Rect(0, 72 - 0, 0) vi=Rect(0, 72 - 0, 0) or=1
10-17 09:43:28.516 30382-30382/com.ktappworks.firebasetest D/ViewRootImpl@949bb67[MainActivity]: MSG_WINDOW_FOCUS_CHANGED 1
10-17 09:43:28.521 30382-30382/com.ktappworks.firebasetest V/InputMethodManager: Starting input: tba=android.view.inputmethod.EditorInfo@6056a6a nm : com.ktappworks.firebasetest ic=null
10-17 09:43:28.521 30382-30382/com.ktappworks.firebasetest I/InputMethodManager: startInputInner - mService.startInputOrWindowGainedFocus
10-17 09:43:28.583 30382-30382/com.ktappworks.firebasetest D/ScrollView: initGoToTop

Nobody here who can help me?

Use getInitialNotification.

eg:

firebase.notifications().getInitialNotification().then((notification) => {
  // Process your message as required
});

thank you this works. But this is still a bug which should be solved.

Duplicate of #1149 and many others, lets track all onNotificationOpened issues in one place please (same platform or not please discuss on #1149).

Thanks

@guitar9 @nik-amir when you guys say this fixes this, are you saying that onNotification is called when your app is in the background, even if the user does not interact with the notification? This is the functionality I've been looking for, but as far as I can tell, it's not possible given the way notifications are handled in Apple's system. They say in the following link that they do not provide a handler for when a notification is simply delivered in the background and every google/SO search indicates the same thing:
https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/SchedulingandHandlingLocalNotifications.html

If you have evidence to the contrary, please let me know!

Was this page helpful?
0 / 5 - 0 ratings