2

在我的一个应用程序中,我想以编程方式获取徽章的整数值(来自推送通知)。

edit:在“应用程序 didReceiveRemoteNotification”中,我必须设置:

badge No. = existing badge No. + 1. 

而且,如何找到这个existing badge No.?任何人都可以帮助...?

提前致谢...

4

2 回答 2

2
[UIApplication sharedApplication].applicationIconBadgeNumber

那是你要找的吗?

APN 中的徽章编号刚刚到达。

AppDelegate

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
    NSDictionary *notification = [userInfo objectForKey:@"aps"];
    //notification is what you want. print it to find out the details. 
    //Title, Badge Count and all that
}
于 2013-02-02T08:27:51.957 回答
0

对于您要查找的内容,这有点准确

appdelegate.m---> 在didfinishlaunching方法中执行此操作:

NSString *badgeCount = [NSString stringWithFormat:@"%li", (long)[[UIApplication sharedApplication] applicationIconBadgeNumber]];
NSInteger countNumber = [badgeCount intValue];

或者,如果您想最初设置 0:

[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
//this will set 0 to initial badge no 
于 2016-05-10T07:20:14.017 回答