1
votes

I am using this package: https://github.com/zo0r/react-native-push-notification to schedule local notifications in my react-native app.

I can schedule local notifications that will display when the app is killed or in the background. If the app is in the foreground the visual notification is suppressed but the notification chime sound plays. I don't want the sound to play - as it can only serve to confuse or annoy the user.

According to Apple docs "The system does not display any alerts, badge the app’s icon, or play any sounds when the app is already frontmost." I've been racking my brain and bingeing on docs but I can't figure out what I could have done to circumvent this iOS policy.

Any ideas where I should look in my code?

1
iOS doesn't play the sound. The sound must be playing either in the package or some place in app code.Raj
That's what I thought as well but the sound plays when the app is killed and a notification pops (as expected) and as far as I can tell there is no function call in my app or the RN-PN package that happens when a notification pops. I'm at a loss as to why and how :-/Lucas Kellner
I seem to have found a solution. In my AppDelegate.m file we are setting up OneSignal properties and by adding kOSSettingsKeyInFocusDisplayOption:@(OSNotificationDisplayTypeNone) to the settings:@{} suppress notifications as desired. The default setting according to OneSignal docs is: OSNotificationDisplayTypeInAppAlert - Display an alert with the notification which seems to have been what was stepping on the iOS notification policies. -- And so it seems this question may not generally be applicable as I don't think many people are mixing multiple notification packages in their app.Lucas Kellner
Cool 8), so the sounds is outRaj

1 Answers

0
votes

This lib has a property that can handle it for you. Just set playSound: false.

You can mix it with AppState to toggle the value according to the state value.

More info in docs below:

https://github.com/zo0r/react-native-push-notification#local-notifications

https://facebook.github.io/react-native/docs/appstate.html

Hope it helps