React-native-push-notification: Custom Notification Sound Not Playing

Created on 12 May 2020  路  15Comments  路  Source: zo0r/react-native-push-notification

Bug

Environment info

react-native info output:

System:
    OS: macOS 10.15.4
    CPU: (4) x64 Intel(R) Core(TM) i5-7267U CPU @ 3.10GHz
    Memory: 84.60 MB / 8.00 GB
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 13.12.0 - /usr/local/bin/node
    Yarn: 1.22.4 - /usr/local/bin/yarn
    npm: 6.14.4 - /usr/local/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  SDKs:
    iOS SDK:
      Platforms: iOS 13.4, DriverKit 19.0, macOS 10.15, tvOS 13.4, watchOS 6.2
    Android SDK:
      API Levels: 15, 23, 24, 26, 27, 28, 29
      Build Tools: 22.0.1, 24.0.1, 27.0.3, 28.0.3, 29.0.2
      System Images: android-28 | Google APIs Intel x86 Atom, android-29 | Google Play Intel x86 Atom
  IDEs:
    Xcode: 11.4.1/11E503a - /usr/bin/xcodebuild
  npmPackages:
    react: 16.13.1 => 16.13.1
    react-native: 0.62.2 => 0.62.2
  npmGlobalPackages:
    react-native-cli: 2.0.1
    react-native: 0.61.4

Library version: 3.4.0

Steps To Reproduce

  1. Put sound.mp3 in iOS Resources/ folder
  2. Call PushNotification.localNotification

Describe what you expected to happen:

I received the notification, but no sound is played. I expected the notification to play my custom sound sound.mp3.

Reproducible sample code

PushNotification.localNotification({
      autoCancel: true,
      smallIcon: 'ic_stat',
      subText: 'Notification',
      color: appColors.accent,
      vibrate: true,
      title: message.data.title,
      message: message.data?.message,
      soundName: 'sound.mp3',
});

Most helpful comment

remove .mp3 ('sound.mp3' to 'sound')
then it works!!!

All 15 comments

Hi @thehappydinoa,
Did you tried the example project? I'm not able to reproduce, maybe a configuration issue.

@Dallas62 I did use almost the same code, my issue is that it plays the sound on Android but not iOS so I am not sure what todo. It has sound notification permissions too.

Did you use XCode to add the sound ?
I think it is not included at build time.

@Dallas62 I did, I actually just used RNFetchBlob to list the contents of the Resources folder on device and sound.mp3 is there along with all my fonts.

I am also able to play the sound manually with:

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

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

You can try to add playSound: true, but if it's not that, the problem is probably from :
https://github.com/react-native-community/push-notification-ios

See: https://github.com/zo0r/react-native-push-notification#ios-manual-installation

If playSound: true works, then I will check the code to fix this since it's the default value...

playSound is set to true, but still no luck, I am trying to manually link, but there may be some issues with Firebase interactions.

@thehappydinoa try to use the sound with other file formats like:

  • .wav (recommended)
  • .aiff
  • .caf

Apple is picky about file formats, maybe this could help.

Make sure that your audio file was added to the "Target Membership" in Xcode otherwise it wont be copied into your app bundle.

Can RN not handle this? Would be cool if we didnt have to copy the files manually into the Xcode world

My custom sound only play in android (foreground & background). No sound in ios device when put custom sound.. default one work.

I test with .wav & .mp3 but both not working.

Hi sorry to hear that,
I suggest you to run example project to see if it works. Then investigate on the difference.
In example project, the sound was imported from XCode into Resources folder, like the documentation suggest it, nothing more.
Since this library doesn鈥檛 implement any ios codebase, you should find in the information in @react-native/react-native-push-ios

I recommend using the react-native-asset library to link the mp3s (and other assets such as fonts).

remove .mp3 ('sound.mp3' to 'sound')
then it works!!!

hey!! @thehappydinoa you're almost there
just put your sound.mp3 file in ios folder and add this file using Xcode.
then hit run!!
it worked for me

Was this page helpful?
0 / 5 - 0 ratings