【问题标题】:How to set a custom sound in react-native-push-notifications remotely如何远程在 react-native-push-notifications 中设置自定义声音
【发布时间】:2020-04-14 23:55:47
【问题描述】:

我已配置远程通知,并且一切正常。现在我想为我的远程通知设置自定义声音。我尝试了很多方法,但这些都不起作用。 我正在使用 react-native-push-notificationreact-native-firebase

我已在android/app/src/main/res/raw/sound.mp3 中放置了一个自定义声音文件。

我也试过soundName:"sound.mp3" 我感谢在这方面的任何帮助。谢谢。 :) 以下是示例代码:

PushNotification.configure({
      onRegister: async function(token) {

      },
      onNotification: function(notification) {
        console.log(notification);
      },
      senderID: 'xxxx',
      permissions: {
        alert: true,
        badge: true,
        sound: true,
      },
      playSound: true,
      soundName: 'sound.mp3',
      popInitialNotification: true,
      requestPermissions: true,
    });
  }````

【问题讨论】:

  • 请分享您的代码
  • @Rajan 服务器端还是客户端?
  • 客户端代码。
  • 请看 :)

标签: android react-native react-native-firebase remote-notifications react-native-push-notification


【解决方案1】:

对于 android,您必须提供带有 channelId: "your-channel-id" 的频道 ID,如果频道不存在,则可能不会触发通知。

注意:如果没有频道,通知可能不起作用

  PushNotification.createChannel(
    {
      channelId: "channel-id", // (required)
      channelName: "My channel", // (required)
      soundName: "sound.mp3",
      importance: 4,
      vibrate: true,
    },
    (created) => console.log(`createChannel returned '${created}'`) // (optional) callback returns whether the channel was created, false means it already existed.
  );

在 soundName 选项中,您为该频道输入自定义声音名称(对于默认声音,使用“默认”),并在发送通知时使用频道 ID

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-19
    • 1970-01-01
    • 2020-07-09
    • 1970-01-01
    • 2021-05-29
    • 1970-01-01
    • 2022-11-30
    相关资源
    最近更新 更多