【问题标题】:Custom Notification Sound Not Playing on iOS for react-native-push-notificationreact-native-push-notification 的自定义通知声音未在 iOS 上播放
【发布时间】:2021-11-19 13:32:02
【问题描述】:

我正在使用 react-native-push-notification npm 包。在创建通知通道时,我正在设置自定义声音的路径,如下所示:

 PushNotification.createChannel(
    {
      channelId: 1, // (required)
      channelName: 'My Channel', // (required)
      channelDescription: 'A channel to categorise your notifications', // (optional) default: undefined.
      soundName: 'tone1', 
      playSound: true, 
      importance: 4,
      vibrate: true, 
    },
    (created) => console.log(`createChannel returned '${created}'`),
  );

对于ios,我将声音添加到XCode中的项目根文件夹如下:

但这不起作用,仍然播放默认声音。在 Android 上,自定义声音正常工作。我什至导入了声音文件并手动播放以确保它正常工作:

import SoundPlayer from 'react-native-sound-player';

SoundPlayer.playSoundFile('tone1', 'mp3');

我什至在 soundName 变量中使用了扩展名 .mp3,但它仍然不起作用。

库版本:7.3.2

【问题讨论】:

    标签: ios react-native push-notification react-native-push-notification


    【解决方案1】:

    我能够让它工作。原来我没有在正确的文件夹中添加声音文件。我们必须将它添加到 ios/ 目录(与 Pods 文件夹相同的级别)。

    此外,当我们安排本地通知时,我还必须传递 soundName 变量。以前,我只是在创建通道时传递变量。

    PushNotification.localNotificationSchedule({
        title: 'Hello',
        message: 'Check Notification' + new Date(Date.now() + 1 * 1000),
        date: new Date(Date.now() + 1 * 1000), // in 1 secs
        allowWhileIdle: false, // (optional) set notification to work while on doze, default: false
        channelId: 'checkNotification',
        soundName: 'tone5.mp3', // (optional) Sound to play
      });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-29
      • 2021-07-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多