7

my AndroidManifest is

enter image description here

in index i wrote AppRegistry.registerHeadlessTask('RNFirebaseBackgroundMessage', () => firebaseBackgroundMessage);

that firebaseBackgroundMessage is a function as below

export async function firebaseBackgroundMessage(message: RemoteMessage) { 
let notif=message['data']; console.log(notif); return Promise.resolve();}

i getting fcm message in background and foreground state but

in closed state is not received any fcm message and in console log i have this error

 No task registered for key RNFirebaseBackgroundMessage

any solution? thank a lot for your help ...

Samira Gheibipour
  • 380
  • 1
  • 3
  • 15

2 Answers2

11

i have a make a mistake in config and i put

AppRegistry.registerHeadlessTask('RNFirebaseBackgroundMessage', () => firebaseBackgroundMessage);

in main.js page and it must be in index.js

and i do it i am so happy to fix it...

thanks to me :)

Samira Gheibipour
  • 380
  • 1
  • 3
  • 15
0

I was also struggling a lot to handle push notification when app is killed, eventually I got the solution.

If we really observe carefully we don't need to register headless task because the package react-native-firebase is already handling it.

All we have to do is add the following lines in your MainActivity.java on native side.

@Override
public void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    setIntent(intent);
    intent.putExtras(this.getIntent());
}

I have a git repo link of mine which has complete set up of notifications, works in all cases i.e, foreground, background, Even app is killed.

https://github.com/venkatesh-u/DeepLinking

  • 1
    i saw your project(thanks a lot) and i build my project again(with i put onNewIntent in MainActivity) but i get that error "No task registered for key RNFirebaseBackgroundMessage" – Samira Gheibipour Sep 28 '19 at 06:31
  • See We really don't need that RNFirebaseBackgroundMessage (headlessTask), Without that we can handle the notifications in all cases i.e, foreground, background, App killed. That's what I put in my case(above link) – UPPALAPU VENKATESH Sep 30 '19 at 12:10