Reputation: 48968
I was looking into ways to send push notifications to a native app and reading the expo documentation, I got confused by two bits of information that seem to contradict each other.
Notifications will appear in the system notification tray as you've come to expect, and tapping them will open/foreground the app.
(source: https://docs.expo.io/versions/latest/guides/push-notifications)
But in the section 'why not expo' it states :
Expo apps don't support background code execution (running code when the app is not foregrounded or the device is sleeping). This means you cannot use background geolocation, play audio in the background, handle push notifications in the background, and more.
(source: https://docs.expo.io/versions/latest/introduction/why-not-expo)
That seems contradictory since 'foregrounding' or 'opening' an app implies that it was running in the background how I see it.
In the end I would like to change the notification badge of an app icon with this, but given this info it's not clear to me if this is possible ? In IOS and Android ?
Upvotes: 5
Views: 15556
Reputation: 21
remove notification badge count for android - Notifications.dismissAllNotificationsAsync()
expo dismissAllNotificationAsync
Upvotes: 2
Reputation: 5090
Indeed foregrounding the app sounds as if the app was actively running in the background and could therefore run code, but as the documentation states, this is not currently feasible with Expo alone. This entails that changing the badge count while the app is in background cannot be done.
On the other hand, when the app is in foreground or the notification is being open, this becomes feasible according to this table in the documentation.
Setting an arbitrary badge count on iOS can be done with Notifications.setBadgeNumberAsync(number)
, whereas for Android the only option available is to make the sent push notifications count towards the badge count for a given channel.
Upvotes: 7