'onNotification' not fired in background - (iOS)
See original GitHub issueI’m using OneSignal to send push notifications to my react-native app. On iOS, everything works really well when the app is in the foreground. When the app is in the background, I see the notification on the lockscreen but my onNotification
is not fired until I open the app (tried it both with the screen on and the screen off)
Haven’t tested this yet on Android
Issue Analytics
- State:
- Created 8 years ago
- Reactions:3
- Comments:16 (5 by maintainers)
Top Results From Across the Web
onNotification() is not fired when app is killed - Stack Overflow
I am not positive but when I remember correctly killing (alias force closing) an app disables the onNotification functionality in Android ...
Read more >Push notification in Background wo… | Apple Developer Forums
When I tap the app and and the app received push notification in Background, that function is called in Active but not called...
Read more >Events | Notifee
Please note, for iOS, the DELIVERED event is not fired for trigger notifications when the app is in the background. App open events....
Read more >Receive messages in an Apple app - Firebase - Google
If you are receiving a notification message while your app is in the background, // this callback will not be fired till the...
Read more >Handling incoming iOS notifications - Pusher Beams Docs
If you take no further action, when your app is running in the background the application:didReceiveRemoteNotification:fetchCompletionHandler: method will not ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Ok, its a bit confusing, but I have both android and iOS notifications working. Here’s what I discovered:
There are 3 types of notification both both iOS and Android. The first type, and the least interesting I guess is the sort that doesn’t make it into your app. They just appear in the notification centre, they can make a noise, vibrate the device and display some text. The android ones can be quite sophisticated. But, basically they look like this (not all possible fields are represented):
iOS:
Android:
The 2nd type are really ones we’re interested in which are the notifications that make their way into you app. They don’t cause any vibrations or make any sound. Now, I believe you can combine the 2 but don’t bother, for reasons I’ll explain below. These look like:
iOS:
Note:
"content-available": 1
is very important here.Android
Note: the absence of a
notification
field is intentional.To get hold of the data in the payload in my
onNotification
method in RN I do something along the lines of:The 3rd and final type is the internal notification, basically your RN app sending a notification to your own device. Now my reason for saying don’t combine type 1 and 2 is that it’s easier and I think better to send an internal notification in response the receiving a type 2 message. If you use an internal notification you have the highest control of what they look like. You can specify sounds, colours, vibrations, message body, message title, numbers etc (again, the android ones can be quite sophisticated but this API doesn’t support it all yet). So when you receive a type 2 notification, in your
onNotification
callback you can then alert the user (if you like) with something noisy and vibraty, like:(Again, not all possible fields are shown in this example)
Note: the
message
field is super important here and is a special field used by this api to populate the text of the internal notification.@npomfret
If you want to do anything in react upon receiving a background fetch you’ll need to retain the completion handler and then call it once your work is done. Calling the completion handler right away causes the app to go straight back into the background.
See this thread: https://github.com/facebook/react-native/issues/1282#issuecomment-189201873
Here’s an example of my implementation: