Refresh icon badge when application is closed

I am trying to update the icon icon for my application (closed) when I received a PN.

I tried adding codes, but it does not work when my application is closed. It works when the application runs in the foreground.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
       NSDictionary *remoteNotif = [launchOptions objectForKey: UIApplicationLaunchOptionsRemoteNotificationKey];

//Accept push notification when app is not open
    if (remoteNotif) {
      [application setApplicationIconBadgeNumber:100];
    return YES;
    }

}
    -(void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
    {

            [[UIApplication sharedApplication] setApplicationIconBadgeNumber: 30];

    }
+1
source share
3 answers

If the application is closed or in the background, a Push notification will not wake it. You need to make this server part and specify the number that you want to see on the icon in your payload:

{
    "aps" : {
        "alert" : "Your notification message",
        "badge" : 1
    }
}

Take a look at the Apple document in the Push Notification Programming Guide

+3
source

applicationIconBadgeNumber = 1 0 didFinishLaunchingWithOptions: , ...

[UIApplication sharedApplication].applicationIconBadgeNumber = 0;
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];

. UILocalNotification ios-badge-number-live-update

RemoteNotifications RemoteNotificationsPG

0

push- iOS, , push-.

But you can send the icon number to the push notification payload, but you will have to run the calculation server command.

The payload might look like this:

    {
       "aps" : {
       "alert" : "You got your emails.",
       "badge" : 1
    }
  }

Now the application app icon icon will display 1.

0
source

Source: https://habr.com/ru/post/1542466/


All Articles