如何处理应用程序图标徽章计数接收推送通知? [英] How to handle App Icon Badge Count on receiving push notification?

查看:75
本文介绍了如何处理应用程序图标徽章计数接收推送通知?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在收到通知时增加徽章数量,并在用户点按或打开应用时减少。

I want to increase the badge count when a notification is received and decrease when user tap or open the app.

我也尝试使用此代码,但它不会工作。

I also try this code but it doesn't work.

-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
    [UIApplication sharedApplication].applicationIconBadgeNumber = [UIApplication sharedApplication].applicationIconBadgeNumber + 1; 
}

推荐答案

根据我的知识,应用程序显示的数字是您在此{{aps:{徽章中发送的徽章计数:{9字典作为徽章价值。

As per my knowledge application is showing number as badge count which is sent by you in this { "aps" : { "badge" : 9 } } dictionary as badge value.

您在此方法中设置的内容

What you are setting in this method

-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
    [UIApplication sharedApplication].applicationIconBadgeNumber = [UIApplication sharedApplication].applicationIconBadgeNumber + 1; 
}

通过点击逻辑上不写的远程通知打开应用程序时设置因为当您打开申请时,您正在设置徽章计数。

is set when you open application by tapping on remote notification which is logically not write because when you are opening application that time you are setting badge count.

您必须在aps字典中传递徽章值,并且您可以在应用程序打开时重置徽章计数(在didFinishLaunchingwithOption方法)。

You must have to pass badge value in your aps dictionary and you may reset badge count when application opened (in didFinishLaunchingwithOption method).

除此之外,没有方法可以在您的应用程序代码中写入,只要您收到推送通知并且您的应用程序是已经处于杀戮模式(根本不打开)。

Apart from this, there is no method you can write in your application code that set badge count as soon as you receive push notification and your application is already in kill mode(not open at all).

这篇关于如何处理应用程序图标徽章计数接收推送通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆