我们如何在应用程序图标中获得徽章通知,类似于标签栏项中的徽章通知。?我需要这个来通知新消息。
问问题
12464 次
2 回答
18
您可以像这样设置应用程序图标的徽章编号:
[UIApplication sharedApplication].applicationIconBadgeNumber = 3;
于 2011-01-25T07:25:00.387 回答
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];
}
迅速:
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) {
// This get's the number you sent in the push and update your app badge.
UIApplication.shared.applicationIconBadgeNumber = (userInfo["badge"] as? NSNumber)?.intValue ?? 0
// Shows an alert in case the app is open, otherwise it won't notify anything
let alertView = UIAlertView(title: "New Notification!", message: (userInfo["aps"] as? [AnyHashable : Any])?["alert"], delegate: self, cancelButtonTitle: "OK", otherButtonTitles: "")
alertView?.show()
}
于 2013-01-26T02:11:56.173 回答