当应用程序不是 运行 时,如何在 React-Native firebase 中设置通知声音

How can I set notification sound when app is not running in React-Native firebase

我正在尝试在 IOS 中未 运行 时让通知响铃。

这是我的代码。

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

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

  });

当应用程序在后台或前台(也许我可以说'app is running')时,通知响起。

我需要使用其他侦听器吗? 还是我需要添加自己的声音文件来响铃?

终于知道怎么做了。 此问题与 react-native-firebase 无关,与我的服务器有关。

当服务器post向应用程序发送消息时,服务器可以设置声音、徽章等多个选项。

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

如果您将声音部分设置为 'default',即使您的应用程序处于后台,您也可以在收到通知时获得默认通知声音。

希望我的回答能对像我这样的react-native-firebase初学者有所帮助

任何人对 FIREBASE 和 REACT NATIVE 有疑问,请尝试通过 Firebase ADMIN SDK 发送您的通知。这适用于 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;
 });