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

查看:20
本文介绍了增加推送通知徽章 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];

认为这应该对您有所帮助.

Think this should help you.

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

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