Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

react native push notification sound

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,
        });
like image 498
b-asaf Avatar asked Aug 09 '17 13:08

b-asaf


1 Answers

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'

like image 152
Nisarg Thakkar Avatar answered Sep 30 '22 18:09

Nisarg Thakkar