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

Badge on App Icon on iOS #488

Open
Richard-Dufour opened this issue Apr 5, 2024 · 1 comment
Open

Badge on App Icon on iOS #488

Richard-Dufour opened this issue Apr 5, 2024 · 1 comment

Comments

@Richard-Dufour
Copy link

Richard-Dufour commented Apr 5, 2024

I cancelled and cleared all my requests, yet the badge number (1) on my iPad always shows up. Even after deleting the app and re-installing it. It is stuck. I no longer have any notifications yet the badge number shows up on my app icon.

The notification clears successfully from the Notification Center, but I still have the badge number on the App icon.

Weird thing is that when I add new requests, the badge number is updated, when I delete requests, once I get to zero, I still see 1.

Also...
Shouldn't the badge number property be part of Current instead of a Request? I mean, the badge is shown on a single app icon (we only see 1 icon displayed, so shouldn't the badge number always be the total number of notification requests? Feels like that property should not even have to be editable, it should just be a read only property that equals:

var current.BadgeNumber = await LocalNotificationCenter.Current.GetDeliveredNotificationList();

I am suspecting there is a bug in a loop of some sort that doesn't clear all the way down to zero.

Ex:
Every time I add a request, I set the BadgeNumber to be the count of await LocalNotificationCenter.Current.GetDeliveredNotificationList();

So add1-> BadgeNumber = 1
Add one more -> BadgeNumber = 2
Add one more -> BadgeNumber = 3

Now, cancel a notification -> BadgeNumber goes to to 2
Cancel another -> BadgeNumber goes to 1
Cancel the last one, -> Badge number is stuck on 1, even weider, sometimes goes back up to 2??

How can I clear the app icon badge once I have removed all my notifications?

Running on Visual Studio 2022 Preview on a Windows 11 machine
Targeted device is an iPad 10th Generation

@Richard-Dufour
Copy link
Author

Richard-Dufour commented Apr 5, 2024

UPDATE:
I found a work around to get the darn iOS app icon to set/clear out.

using System;

public static async void RefreshBadge()
 {
     //Called on MainPage OnAppearing and also when I click/tap on a notification
     var delivered = await LocalNotificationCenter.Current.GetDeliveredNotificationList();
     int newBadgeNumber = delivered.Count();

     //They all should have the same BadgeNumber -> The overall total number of notifications
     for (int i = delivered.Count - 1; i >= 0; i--)
     {
         var deliveredNotification = delivered[i];
         deliveredNotification.BadgeNumber = newBadgeNumber;
     }

     // Badge comes from using system, it is needed (at least on iOS) to set/clear the Badge number properly on my iPad
     Badge.Default.SetCount((uint)newBadgeNumber);
     Badge.SetCount((uint)newBadgeNumber);
 }

private void ClearAppBadgeCount()
{
    Badge.Default.SetCount(0);
    Badge.SetCount(0);
}

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