Update badge icon when app is closed

非 Y 不嫁゛ 提交于 2019-11-28 14:20:08

If you app is closed or in the background, a Push notification won't wake it up. You need to do this server side and include the number you want to see on icon in your notification payload:

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

Have a look at the Apple doc on Push Notification programming guide

Paras Joshi

for that set applicationIconBadgeNumber = 1 or 0 in didFinishLaunchingWithOptions: method like bellow...

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

See Another answer for UILocalNotification From this link ios-badge-number-live-update

Also another link for RemoteNotifications from this link RemoteNotificationsPG Guide

Since push notification are handled by iOS and not your app you can't change the application badge on receiving a push notification.

But you can send the badge number in the payload of the push notification, but the you will have to do the calculation server side.

The payload could look like this:

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

Now the app application badge icon will show 1.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!