反应本机推送通知声音 [英] react native push notification sound

查看:97
本文介绍了反应本机推送通知声音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将声音添加到本地推送通知中。
我使用RN 0.45.1和
react-native-push-notifications 3.0.0



我设法在iOS和Android中安排通知默认声音。
我没有设法添加自定义声音。



我有声音类型为mp3的文件。
我尝试了以下内容:


  1. 将文件放在我的项目文件夹中:
    '/ src / assests / sounds /sound.mps'(我项目中的一个文件夹)

而不是:

 从'../src/assests/sounds/sound.mps'导入notificationWound; 

PushNotification.localNotificationSchedule({
message:'测试消息',
日期:新日期(Date.now()+(60 * 1000)),
repeatType:'time',
repeatTime:60 * 1000,
sound:notificationSound,
});




  1. 另一次尝试是:
    put android文件夹下的声音文件:.. \ android \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ $ b

    ,通知是:

      PushNotification.localNotificationSchedule({
    message:'Test message',
    date:new Date(Date.now()+(60 * 1000)),
    repeatType:'time',
    repeatTime:60 * 1000,
    sound:sound。 mp3,
    });


    解决方案

    有声音属性



    soundName:'default',



    通知时播放的声音所示。
    'default'的值播放默认声音。
    它可以设置为自定义声音,例如android.resource://com.xyz/raw/my_sound'。它将在'res / raw'目录中查找'my_sound'音频文件并播放它。默认值:'默认'(播放默认声音)



    自定义声音



    在android中,添加自定义声音文件到[project_root] / android / app / src / main / res / raw



    在iOS中,将自定义声音文件添加到xCode中的项目资源。



    在位置通知中,json指定完整的文件名:



    soundName:'my_sound.mp3'


    I am trying to add sound to my local push notification. I am using RN 0.45.1 and react-native-push-notifications 3.0.0

    I manage to schedule notification in iOS and Android with default sound. I did not manage to add custom sound.

    I have sounds file of type mp3. I tried the following:

    1. place the file in my project folder: '/src/assests/sounds/sound.mps' (a folder inside my project)

    and than:

    import notificationSound from '../src/assests/sounds/sound.mps';
    
    PushNotification.localNotificationSchedule({
                message: 'Test message',
                date: new Date(Date.now() + (60 * 1000)),
                repeatType: 'time',
                repeatTime: 60 * 1000,
                sound: notificationSound,
            });
    

    1. another attempt was: putting the sound file under android folder: ..\android\app\src\main\res\raw\sound.mp3

    and the notification was:

       PushNotification.localNotificationSchedule({
                message: 'Test message',
                date: new Date(Date.now() + (60 * 1000)),
                repeatType: 'time',
                repeatTime: 60 * 1000,
                sound: sound.mp3,
            });
    

    解决方案

    There is property for sound

    soundName: 'default',

    Sound to play when the notification is shown. A value of 'default' plays the default sound. It can be set to a custom sound such as android.resource://com.xyz/raw/my_sound'. It will look for the 'my_sound' audio file in 'res/raw' directory and play it. default: 'default' (default sound is played)

    For Custom sounds

    In android, add your custom sound file to [project_root]/android/app/src/main/res/raw

    In iOS, add your custom sound file to the project Resources in xCode.

    In the location notification json specify the full file name:

    soundName: 'my_sound.mp3'

    这篇关于反应本机推送通知声音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆