我们如何在应用图标中获取徽章通知,类似于tabbar项目中的徽章通知。我需要这个来通知新消息。
答案 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];
}