I have received push notification in my iphone app but badge number is not shown over icon when got notification.when i click the notification to open the app and close it,then badge is shown.my push notification payload format is
{
"aps" : {
'alert' => $message,
'sound' => 'default',
'badge' => 1
},
'plsID' : '105',
}
and my code for showing badge is
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
for (id key in userInfo) {
NSLog(@"key: %@, value: %@", key, [userInfo objectForKey:key]);
[UIApplication sharedApplication].applicationIconBadgeNumber = [[[userInfo objectForKey:@"aps"] objectForKey: @"badge"] intValue];
}
}
I was facing same problem. I tried below code and got it worked
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.