未显示图标上的iOS推送通知徽章编号

时间:2013-11-26 19:34:48

标签: ios iphone objective-c

我在我的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];
    }
}

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题。我尝试了下面的代码,并使其工作

[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];