Increment the Push notification Badge iPhone

后端 未结 5 1401
礼貌的吻别
礼貌的吻别 2020-11-29 00:17

Is it possible to increment the badge value on receiving the notification. OR Should I send the count as payload?

If i am sending the badge value as \"1\" every time

相关标签:
5条回答
  • 2020-11-29 00:44

    Usually in all apps the unread notification counts are maintained in the server. When the server sends a push notification to a particular device token they send the badge count along with the payload. Once the device is notified and your app is in background(or killed) the OS automatically update the badge count to your app icon. In case whether you have your app running, you will get notified in the

    application:didReceiveRemoteNotification:
    

    delegate and thus you are able to receive the badge count from the (NSDictionary *)userInfo. And thus you are able to update the app icon badge count using the function

    [UIApplication sharedApplication].applicationIconBadgeNumber = [[[userInfo objectForKey:@"aps"] objectForKey: @"badgecount"] intValue];
    

    Think this should help you.

    0 讨论(0)
  • 2020-11-29 00:55

    After receiving remote Notification when you open App,

    get current Badge number in "didBecomeActive" Method of your Appdelegate File using below code:

    int badgeCount = [UIApplication sharedApplication].applicationIconBadgeNumber;
        badgeCount = badgeCount + 1;
    
    0 讨论(0)
  • 2020-11-29 01:05

    Urban Airship supports this using their "autobadge" feature.

    0 讨论(0)
  • 2020-11-29 01:07

    If the application is not open you will not be able to increase the badge except from the payload.

    0 讨论(0)
  • 2020-11-29 01:07

    When a Push Notification comes while your application is in background mode & you want to increment the Badge Number, you should send a badgeCount to the server, so that the server knows the current count.

    If you manage the badge count from the Server Side then this code is enough:-

    - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo  {
        NSLog(@"remote notification: %@",[userInfo description]);
    
        if (userInfo) {
            NSLog(@"%@",userInfo);
    
            if ([userInfo objectForKey:@"aps"]) { 
                if([[userInfo objectForKey:@"aps"] objectForKey:@"badgecount"]) {
                    [UIApplication sharedApplication].applicationIconBadgeNumber = [[[userInfo objectForKey:@"aps"] objectForKey: @"badgecount"] intValue];
                }
            }
        }
    }
    
    0 讨论(0)
提交回复
热议问题