首页 > 解决方案 > 通知声音在本机 Firebase v6 中不起作用?

问题描述

我正在向收到通知的用户发送通知,但没有任何声音“默认设备声音”

我添加了一个sound: 'default'通知有效负载,但仍然无法正常工作!

这是我的功能

// Send notification for user when his order is accepted "status : pendding"
exports.acceptOrder = functions.database
  .ref('/Providers/ProvidersOrders/InProgress/{providerUid}/{orderId}')
  .onCreate(async (snapshot, context) => {
    console.log('snapshot', snapshot.val());
    const {userUID} = snapshot.val();

    const userRef = await admin
      .database()
      .ref(`/users/${userUID}`)
      .once('value');

    const {userToken, username} = userRef.val(); // FCM user app token

    try {
      const options = {
        priority: 'high',
        contentAvailable: true,
      };
      const payload = {
        notification: {
          title: 'Accepted order',
          body: `Hey! ${username}, your order has accepted we will contact with you as soon as possible.`,
          timestamp: Date.now().toString(),
          isRead: 'false',
          sound: 'default',
        },
      };

      let {sound, ...notification} = payload.notification;
      let uid = userUID;

      await admin
        .messaging()
        .sendToDevice(userToken, payload, options)
        .then(() => {
          return admin
            .database()
            .ref(`Notifications/${uid}`)
            .push({...notification});
        });
      console.log('message sent');

    } catch (error) {
      console.log('Error sending message:', error);
    }
    return null;
  });

那么这里有什么问题呢?

标签: androidfirebasereact-nativefirebase-cloud-messagingreact-native-firebase

解决方案


推荐阅读