增加推送通知徽章iPhone [英] Increment the Push notification Badge iPhone

查看:117
本文介绍了增加推送通知徽章iPhone的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在收到通知时增加徽章值。或者我应该将计数作为有效载荷发送吗?

Is it possible to increment the badge value on receiving the notification. OR Should I send the count as payload?

如果我每次都将徽章值发送为1,我怎么能增加徽标值的图标应用程序未打开时的应用程序。

If i am sending the badge value as "1" every time, how could i increment the badge-value in the icon of the app if the app is not open.

我已使用此代码但无效。

i have used this code but doesn't work.

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


推荐答案

通常在所有应用中未读通知计数在服务器中维护。当服务器向特定设备令牌发送推送通知时,他们会发送徽章计数以及有效负载。一旦设备被通知并且您的应用程序处于后台(或被杀死),操作系统会自动将徽章计数更新为您的应用程序图标。如果您的应用程序是否正在运行,您将收到

Usually in all apps the unread notification counts are maintained in the server. When the server sends a push notification to a particular device token they send the badge count along with the payload. Once the device is notified and your app is in background(or killed) the OS automatically update the badge count to your app icon. In case whether you have your app running, you will get notified in the

application:didReceiveRemoteNotification:

委托,因此您可以从(NSDictionary *)userInfo接收徽章计数。因此,您可以使用函数更新应用程序图标徽章计数

delegate and thus you are able to receive the badge count from the (NSDictionary *)userInfo. And thus you are able to update the app icon badge count using the function

[UIApplication sharedApplication].applicationIconBadgeNumber = [[[userInfo objectForKey:@"aps"] objectForKey: @"badgecount"] intValue];

认为这可以帮到你。

这篇关于增加推送通知徽章iPhone的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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