React-native-push-notification: Cannot make notification silent

Created on 9 Feb 2021  路  9Comments  路  Source: zo0r/react-native-push-notification

Question

Hi, I've been trying to make a notification that doesn't make any sound, but couldn't accomplish it since the library uses channel system on Android.

Ideally I'd like to control the soundName and playSound configuration of the notification through notification configuration object, but apparently on Android it's now bound to the channel configuration. So to have different values for soundName it should be done by providing separate channel for each value.

However, one thing that I can't do is disabling the sound of the notification, even tho I explicitly set the value when creating the channel

PushNotification.createChannel({
    channelId: 'channelidhere', // (required)
    channelName: 'channel name', // (required)
    playSound: false,
    soundName: 'default', // (optional) See `soundName` parameter of `localNotification` function
    importance: 4, // (optional) default: 4. Int value of the Android notification importance
  });
PushNotification.localNotification({
      channelId: 'channelidhere',
      title: 'Test',
      message: 'Test',
      playSound: false,
    });

it seems that the playSound property is disregarded, since the notification would still come with a sound.

The only way that I can disable the sound is by setting the importance to low (2), but this makes the notification heads-up doesn't appear. Is there a way to properly disable the sound while still showing the notification heads-up?

platform: Android
"react-native-push-notification": "^6.1.1",

Most helpful comment

Hi @eyalyoli
I published a release to fix your issue.
Regards,

All 9 comments

Hi @nastarfan,
Make sure your channel wasn't already created with a sound by changing the id of the channel (playSound: false).
Channels can't be updated.
Regards,

On android it is easy to control the sound with channel configuration (cannot be overridden by the local notification).

But it is needed for iOS, and I did check this, playSound doesn't work! I browsed the code, it seems that it sets sound = '', but according to Apple's docs on the sound key:

Include this key when you want the system to play a sound ... If the sound file cannot be found, or if you specify default for the value, the system plays the default alert sound.

What I understand is to stop the sound we should remove sound key at all...
What do you think @Dallas62?

Hi @nastarfan,
Make sure your channel wasn't already created with a sound by changing the id of the channel (playSound: false).
Channels can't be updated.
Regards,

Yeah I read in the docs about that, I have tried uninstalling and reinstalling the app after making the change i.e. playSound: false, but still can't disable the sound with importance level of 4.

Hi @nastarfan
Can you try with another device ? (reset simulator)
It's possible that the channels preference are stored in the device. Changing the id of the channel is another way to test.

@Dallas62 thanks for your suggestion, I tried changing the id of the channel to a newly created one, it still produces the sound.
Maybe it's overridden by importance value configuration for the channel?

hi @Dallas62 many thanks for your help! updating to the new version solves the issue. Sorry I didn't notice the change in changelog, that's why I didn't update.

Apparently there's another issue raised by other user, I'll keep this issue opened

Hi @eyalyoli
I published a release to fix your issue.
Regards,

Was this page helpful?
0 / 5 - 0 ratings