How can I set notification sound when app is not r

2019-08-03 17:59发布

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?

1条回答
Root(大扎)
2楼-- · 2019-08-03 18:20

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.

查看更多
登录 后发表回答