如何在应用程序图标中显示通知计数?

时间:2016-01-06 08:54:11

标签: ios objective-c push-notification apple-push-notifications

我想像这样显示推送通知计数,我已经搜索了它但无法获得正确的解决方案。

enter image description here

4 个答案:

答案 0 :(得分:5)

你可以随处设置它。 E.g:

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

{
    [[UIApplication sharedApplication] setApplicationIconBadgeNumber:123]; // this one
} 

答案 1 :(得分:3)

当您收到通知时,会调用此方法:

application:didReceiveRemoteNotification:

这将包含NSDictionary

`(NSDictionary *)userInfo`

使用

功能更新应用图标徽章计数
[UIApplication sharedApplication].applicationIconBadgeNumber = [[[userInfo objectForKey:@"aps"] objectForKey: @"badgecount"] intValue];

您的有效负载如下所示:

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

要隐藏徽章,请使用零(0)

答案 2 :(得分:1)

它叫做徽章,你可以写下面一行来实现这个目标:

 private static void Main(string[] args)
        {
            new Check().UseDelegate();
        }

如果您想了解其在样本申请中的工作情况,请参阅以下链接:

http://www.touch-code-magazine.com/how-to-add-a-badge-to-the-application-icon/

答案 3 :(得分:0)

在Swift 4中,您可以通过添加以下行来设置徽章:

>>>>import rae
>>>>help(rae)

Help on package rae:

NAME
    rae - # -*- coding: utf-8 -*-

FILE
    /home/sahil/.local/lib/python2.7/site-packages/rae/__init__.py

PACKAGE CONTENTS


CLASSES
    __builtin__.object
        Article
        DA
        DEJ
        DLE
        DPD

    class Article(__builtin__.object)
     |  Methods defined here:
     |