5

I'm trying to make notification ringing when app is not running in IOS.

Here is my code.

  this.notificationListener = firebase.notifications().onNotification((notification: Notification) => {

    // SET SYSTEM DEFAULT SOUND!
    notification.setSound("default");
    firebase.notifications().displayNotification(notification);

  });

When app is in background or foreground ( Maybe I can say 'app is running'), notification rings well.

Should I need to use other listener? Or should I need to add my own sound file for ringing?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
newbeeep
  • 585
  • 1
  • 6
  • 15

2 Answers2

4

Finally, I know how to do this. This issue was not related to react-native-firebase, it was related to my server.

When server post message to app, server can set several options like sound, badge.

https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CommunicatingwithAPNs.html#//apple_ref/doc/uid/TP40008194-CH11-SW1

If you set sound section to 'default', you can get default notification sound when notification is coming even if your app is on background.

I hope my answer can help react-native-firebase beginners like me.

newbeeep
  • 585
  • 1
  • 6
  • 15
1

Anyone Has issue with RNFIREBASE & REACT NATIVE, Try to send your notification via Firebase ADMIN SDK. That will work for Sure

  //Notification Payload
  const payload = {
       notification: {
            title: update.title,
            body: update.body,
            icon: "default",
            badge: '1',
            sound: 'default' // notification sound 
        },
  };
  
  //sending notification via Firebase Admin SDK
  admin.messaging().sendToDevice('TOKEN_OR_TOKENS', payload)
    .then( () => { return true; }).catch(function() {
        console.log('error sendToDevice() ')
        return null;
 }); 
Joel Jerushan
  • 645
  • 11
  • 21