如何在expo react-native-app中收到FCM通知时禁用声音

问题描述 投票:0回答:1

我正在使用 firebase admin 从 dotnet 服务器发送通知来反应本机应用程序。在每种情况下(前景、背景、死机)一切都工作正常,但我希望用户能够在应用程序处于后台或死机时禁用通知中的声音。我尝试在 dotnet 服务器中不包含声音选项,但我仍然听到声音。请帮助我,我被困了好几个小时,这是我服务器上的代码

    var messaging = FirebaseMessaging.DefaultInstance;
    var message = new Message()
    {
        Notification = new Notification
        {
            Title = notificationToBeSent.Title??string.Empty,
            Body = notificationToBeSent.Message ?? string.Empty
        },
        Data = notificationToBeSent.Data,
        Token = notificationToBeSent.RecipientId// "TARGET_DEVICE_TOKEN" // Replace with 
    };
    var result = await messaging.SendAsync(message);

在我的 React Native 应用程序中,我使用了来自“@react-native-firebase/messaging ani”的消息传递,我注意到通知模块已被弃用,因此包含该选项的每个解决方案都不再有效。我的 React Native 应用程序中用于处理后台通知的代码是这样的。

     messaging().setBackgroundMessageHandler(async remoteMessage => {
         console.log("......",remoteMessage.notification?.android?.sound)
         console.log('Message handled in the background!', 
          remoteMessage.notification?.android?.sound);});

声音未定义,但我仍然听到设备的默认通知。

javascript react-native expo firebase-cloud-messaging react-native-firebase
1个回答
0
投票

有解决办法

const notify = {
     ...message.notification,
     show_in_foreground: true,
     notify_type: message.NotificationType,
     obj_id: message.ObjectId,
     sound: '' // remove this
};
firebase.messaging().createLocalNotification(notify);
© www.soinside.com 2019 - 2024. All rights reserved.