SetApplicationIconBadgeNumber has no effect

I am experimenting with cleaning notifications from the notification center (in cases where workarounds include setting the icon number to 0, since there is no api to delete them).

However, during the experiments, I noticed that I can not get setApplicationIconBadgeNumber to have any effect on the icon number.

For example, if I have:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{    
      [[UIApplication sharedApplication] setApplicationIconBadgeNumber: 5];

(and setApplicationIconBadgeNumber is no longer called)

then the icon for the icon is missing, not to mention the one containing the number.

(Notifications do not set the icon number, perhaps there must be an icon number first before setApplicationIconBadgeNumber: has any effect, can anyone confirm or refute this?)

UPDATE :, I noticed this in the console, possibly related to it:

May 24 16:12:49 unknown installd[138] <Error>: entitlement 'aps-environment' has value not permitted by a provisioning profile
May 24 16:12:49 unknown SpringBoard[51] <Warning>: Killing com.mycompany.xxx for termination assertion
May 24 16:12:50 unknown installd[138] <Error>: entitlement 'aps-environment' has value not permitted by a provisioning profile
May 24 16:12:50 unknown SpringBoard[51] <Warning>: Reloading application state for 'com.mycompany.xxx' as its modification date or path has changed
May 24 16:12:50 unknown SpringBoard[51] <Warning>: Reloading and rendering all application icons.

, , , , .., Xcode.

+3
4

setApplicationIconBadgeNumber iOS8 +, , iOS8:

UIUserNotificationType userNotificationTypes = UIUserNotificationTypeBadge;
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes categories:nil];
[application registerUserNotificationSettings:settings];
+10

.

[UIApplication sharedApplication].applicationIconBadgeNumber++;    

, , , .

, .

+2

.

:

[[UIApplication sharedApplication] setApplicationIconBadgeNumber: 5];

, , . :

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

It is executed only if the application is completely closed. During testing, because you have a lot in and out of it, the application may go into the background and be paused, in which case call it also:

- (void)applicationDidBecomeActive:(UIApplication *)application 

Hope this helps.

+2
source

I just found out that it must be a number> 0. It did not work with a negative number.

0
source

All Articles