1

我正在从服务器端向 apns 服务器发送通知,我在处理徽章时遇到了一个小问题,如果用户在通知中心看到通知,我的徽章数量应该减少,如果应用程序已经在运行,我认为不需要徽章,但我的徽章号码总是“1”

从我的服务器端我发送徽章 =“1”。如何通知服务器我的应用程序具有特定的徽章编号,如何知道我的徽章编号。

        - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
     {
 NSLog(@"%@",userInfo);
UIApplicationState state = [application applicationState];
[[UIApplication sharedApplication]setApplicationIconBadgeNumber:1];
if (state == UIApplicationStateActive) {
    [[UIApplication sharedApplication]setApplicationIconBadgeNumber:0];





    NSString *message = [[userInfo valueForKey:@"aps"] valueForKey:@"alert"];
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@""
                                                        message:message
                                                       delegate:self
                                              cancelButtonTitle:@"Ok"
                                              otherButtonTitles: nil];
    [alertView show];
    [alertView release];

}

}

4

1 回答 1

1

通常在所有应用程序中,未读通知计数都保存在服务器中。当服务器向特定设备令牌发送推送通知时,服务器将徽章计数与有效负载一起发送。

您的服务器逻辑需要跟踪正确的徽章计数并适当地发送。

{
    "aps" :  
    {
        "alert" : "Your notification message",
        "badge" : badgecount ,
        "sound" : "bingbong.aiff"
    }
}

而是在您的代码中[[UIApplication sharedApplication]setApplicationIconBadgeNumber:1]; 使用

badge_value+=[[[userInfo objectForKey:@"aps"] objectForKey:@"badge"]intValue];
    [UIApplication sharedApplication].applicationIconBadgeNumber = badge_value;

其中,badge_value 是存储徽章值的整数。

于 2013-07-30T10:23:23.620 回答