Do not show alert icons

I use this encoding to notify Apple push, push notifications come, but they come without any badges, any suggestions what is wrong with this code that I do not receive badges. I already check the settings tab and the icons are displayed there.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)]; [UIApplication sharedApplication].applicationIconBadgeNumber = 0; } - (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken1 { NSString *str = [NSString stringWithFormat:@"%@",deviceToken1]; NSLog(@"%@",str); self.deviceToken = [NSString stringWithFormat:@"%@",str]; NSLog(@"dev --- %@",self.deviceToken); self.deviceToken = [self.deviceToken stringByReplacingOccurrencesOfString:@"<" withString:@""]; self.deviceToken = [self.deviceToken stringByReplacingOccurrencesOfString:@" " withString:@""]; self.deviceToken = [self.deviceToken stringByReplacingOccurrencesOfString:@">" withString:@""]; NSLog(@"dev --- %@",self.deviceToken); } - (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err { NSString *str = [NSString stringWithFormat: @"Error: %@", err]; NSLog(@"%@",str); } - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { NSLog(@"Received notification: %@", userInfo); //[self addMessageFromRemoteNotification:userInfo]; NSString* alertValue = [[userInfo valueForKey:@"aps"] valueForKey:@"badge"]; NSLog(@"my message-- %@",alertValue); int badgeValue= [alertValue intValue]; [[UIApplication sharedApplication] setApplicationIconBadgeNumber:badgeValue]; } 
+6
source share
2 answers

There was a problem with server-side coding, as I just found out that the icon value must be implicitly set as an integer to get the desired result.

How do I get a null value in the value of the icon.

+7
source

I ran into this problem before, hope this helps

 {"aps":{"alert":"dsfdsfsdfsdfsdfdfdfsdfsdf","badge":1,"sound":"a"}} 

make sure there is no double quote mark in the icon

+1
source

Source: https://habr.com/ru/post/910888/


All Articles