在Iphone应用程序中的应用程序图标上的徽章

时间:2011-01-25 07:19:32

标签: iphone push-notification badge

我们如何在应用图标中获取徽章通知,类似于tabbar项目中的徽章通知。我需要这个来通知新消息。

2 个答案:

答案 0 :(得分:18)

您可以设置应用图标的徽章编号,如下所示:

[UIApplication sharedApplication].applicationIconBadgeNumber = 3;

答案 1 :(得分:3)

如果您想通过PUSH消息输入徽章编号,可以将PUSH发送为:

{"aps":{"alert":"My Push Message","sound":"default","badge",3}}

然后在AppDelegate中添加以下内容:

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

// This get's the number you sent in the push and update your app badge.
[UIApplication sharedApplication].applicationIconBadgeNumber = [[userInfo objectForKey:@"badge"] integerValue];

// Shows an alert in case the app is open, otherwise it won't notify anything
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"New Notification!"
                                              message:[[userInfo objectForKey:@"aps"] objectForKey:@"alert"]  delegate:self
                                              cancelButtonTitle:@"OK"
                                              otherButtonTitles:nil];
[alertView show];    
}