Home > Software engineering >  Using Xamarin Essentials Preferences for Notification Badge Count
Using Xamarin Essentials Preferences for Notification Badge Count

Time:11-17

I've an app which receives notifications and have been trying to build the badge count locally on the app.

Within the App Delegate on iOS, I have the following

   
int notifcount = Preferences.Get("notifcount", 0);
                
UIApplication.SharedApplication.ApplicationIconBadgeNumber = notifcount  1;

        
Preferences.Set("notifcount", notifcount   1);

This is placed in the methods DidReceiveRemoteNotification & WillPresentNotification.

Everything seems to work fine in debug mode - I receive notifications and the badge increments. However, when I release the app on Test Flight the behaviour changes - some users report the badge working fine, some get the badge incrementing sometimes and some don't get it at all.

I know ideally the badge would be passed along with the payload (but the app doesn't have user accounts yet).

My question is there limitations to Xamarin Essentials Preferences that stop it being used this way or something within iOS that could be causing this behaviour?

Thanks!

CodePudding user response:

For iOS, the badge count is managed by iOS itself, and it is completely OS dependent when the app is in the background or killed. You can send the badge count in the payload of the push notification, but you should do the calculation on the server side.

  • Related