Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to increment badge when app not in foreground #146

Open
timstoute opened this issue Apr 20, 2021 · 1 comment
Open

How to increment badge when app not in foreground #146

timstoute opened this issue Apr 20, 2021 · 1 comment

Comments

@timstoute
Copy link

I'm trying to set the badge count for the user when the app is running in the background. But it's not working.

I'm using Firestore, and save the user-specific number of new messages the user has as a field on the Firestore user document. This is an Ionic Cordova app.

The following code works when the app is in the foreground, but not when the app is running in the background on the IOS device.

In app.component.ts I have code like:

` if ((this.platform.is('ios')) || (this.platform.is('android'))) {
this.appBadge.requestPermission()
.then(async result => {

          if (this.appBadge.hasPermission()) {

            // get appBadge count for user 
            await this.auth.user$?.subscribe(user => {
              this.user = user;

              this.common.getUserChatNotifications(user).subscribe(
                chatNotificationCount  => {
                 // set the badge value
                 this.appBadge.set(chatNotificationCount)
                  })
        })

...`
What am I missing?

@timstoute
Copy link
Author

it looks like Firebase Cloud Messaging supports setting badge values, and that looks like the best way to achieve both notifications and badges when the app is not running or not in the foreground:https://firebase.google.com/docs/cloud-messaging/http-server-ref#notification-payload-support

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant