iPhone应用程序中的应用程序图标徽章

问题描述:

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

您可以设置应用程序图标的证件号码这样的:

[UIApplication sharedApplication].applicationIconBadgeNumber = 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];  
}