我在我的iphone应用程序中收到了推送通知,但是当收到通知时,徽章编号没有显示在图标上。当我点击通知打开应用程序并关闭它时,会显示徽章。我的推送通知有效载荷格式是
{
"aps" : {
'alert' => $message,
'sound' => 'default',
'badge' => 1
},
'plsID' : '105',
}
我显示徽章的代码是
- (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];
}
}
答案 0 :(得分:0)
我遇到了同样的问题。我尝试了下面的代码,并使其工作
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];