ApplicationIconBadgeNumber is not getting reset on

2019-08-10 14:53发布

问题:

I'm setting my applicationIconBadgeNumber using this code:

[[UIApplication sharedApplication] setApplicationIconBadgeNumber:theIntToDisplay];

The problem is that when I delete the app from an iPad and reinstall it, the app icon still shows the previous badge number. Is this default iOS behavior or can we reset it?

I found one similar question on at Why the applicationIconBadgeNumber is not getting deleted with appliccation ? Where it stored actually?, but it didn't answer my question.

回答1:

This is an expected behavior, the badge number remains for a short period after uninstall e.g for the case of an immediate re-install.

Of course you can nullify badge number after every launching the application in application:didFinishLaunchingWithOptions: method but I think it is not the case because you want badge number not to be shown right after you install app and not yet launch it. In such a case just wait after removing the application and the badge numbers cache will be cleared by iOS and then install the app again. Unfortunately without jailbreaking the device there is no way to manage badge numbers behavior manually



回答2:

In your app delegate under:

- (void)applicationWillEnterForeground:(UIApplication *)application
{

}

Insert:

application.applicationIconBadgeNumber = 0;