Как мы можем получить уведомление о значке на значке приложения, аналогичном уведомлению о значке в элементе панели вкладок? Мне нужно это для уведомления о новых сообщениях.
Значок на значке приложения в приложении для iPhone
Ответы (2)
Вы можете установить номер значка значка приложения следующим образом:
[UIApplication sharedApplication].applicationIconBadgeNumber = 3;
person
Di Wu
schedule
25.01.2011
как это сделать динамическим?
- person ; 23.07.2019
Если вы хотите поместить номер значка в 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()
}
person
gmogames
schedule
26.01.2013