如何在ios 7中运行应用程序时更新applicationbadge编号?

时间:2015-03-12 14:41:49

标签: ios push-notification apple-push-notifications

我的aps词典

{
aps =     {
    alert = "My first push notification!";
    "content-available" = 1;
    sound = default;
};

}

我在以下方法中有更新徽章计数

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler

当应用程序运行时它工作正常。但是当我杀死我的应用程序然后杀死应用程序后我试图发送push-notification.i收到通知栏上的推送通知,但我的徽章号码没有更新。  更新徽章我的代码如下。

    - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler
{
   [AppCommon saveToUserDefaults:[NSString stringWithFormat:@"%d",[[AppCommon readFromUserDefaultsForKey:@"bagecount"] intValue] + 1] forKey:@"bagecount"];
    int count = [[AppCommon readFromUserDefaultsForKey:@"bagecount"] intValue];
    NSLog(@"Set Badge %d",count);
    [[UIApplication sharedApplication] setApplicationIconBadgeNumber: count];
}

1 个答案:

答案 0 :(得分:2)

您应该将徽章信息放在通知有效负载中,如下所示:

{
aps =     {
    alert = "My first push notification!";
    "content-available" = 1;
    "badge" : 1
    sound = default;
};