I have a badge on my Xamarin.iOS app that shows how many unread notifications there are. I'm using UIApplication.SharedApplication.ApplicationIconBadgeNumber to set the badge count when the app starts up and whenever the unread notifications count changes. If I delete the app when the badge is showing 2 unread notifications, and I re-install it, the app icon still shows the 2 unread notifications from the old install. What needs to be done so a new install accurately shows no unread notifications (and no badge showing)?
Asked
Active
Viewed 232 times
1 Answers
0
You could define a property in the app by using NSUserDefaults . The property will been created when you first load the app and been moved when uninstall it .
var plist = NSUserDefaults.StandardUserDefaults;
if(plist.BoolForKey("IsNeedSetBadge"))
{
//set badge
}
else
{
//first load , set this value
plist.SetBool(true, "IsNeedSetBadge");
}

Lucas Zhang
- 18,630
- 3
- 12
- 22
-
The problem is, the badge icon is showing unread notifications after a delete/re-install, **before** the app has been run for the first time after the re-install. The app would have to run to execute the code you are suggesting. – MSibalik Mar 25 '21 at 11:54
-
If so you could use keychain . Check https://stackoverflow.com/questions/41336016/cant-access-saved-in-a-xamarin-ios-keychain-value . – Lucas Zhang Mar 30 '21 at 01:59