Iphone app icon icon

How can we get a notification about the icon in the application icon, similar to the notification of the icon in the panel element.? I need this to notify new posts.

+6
iphone push-notification badge
source share
2 answers

You can set the application icon icon icon as follows:

[UIApplication sharedApplication].applicationIconBadgeNumber = 3; 
+19
source share

If you want to put the badge number in PUSH messages, you can send PUSH as:

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

Then in your AppDelegate you add the following:

 - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{ // This get 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]; } 

soon:

 func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) { // This get 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() } 
+3
source share

All Articles