How to increase badge number when application is in background

前端 未结 3 1586
天涯浪人
天涯浪人 2021-02-10 19:32

I am using this code. Every thing is working fine when push notification comes but badge number does not increase when application is in background. How to solve this problem? <

相关标签:
3条回答
  • 2021-02-10 19:38

    When the application is in the background didFinishLaunchingWithOptions method never calls. For doing something when your App is in background you need to implement your logic in AppDelegate's applicationDidEnterBackground: method like.

    - (void)applicationDidEnterBackground:(UIApplication *)application{
    
    [UIApplication sharedApplication].applicationIconBadgeNumber = 2;
    }
    
    0 讨论(0)
  • 2021-02-10 19:45

    You can't increase the badge number using code when app is in background or closed state.But the badge can be increased by value in notification payload.No code will execute during this state and Push notification is handled by OS itself. This link have the same issue and resolved.

    Check whether the push notification payload contains application badge field and set to values greater than 0.If its 0,then badge number will be 0 when app in background or closed.

    0 讨论(0)
  • 2021-02-10 19:52

    When you send a Push Notification you need add badge value. So you need handle badge for each user device. In php is something like that:

    $body['aps'] = array(
    'alert' => $message,
    'sound' => 'default',
    'badge'=> 10
    );
    

    where 10 thats just the number displayed in the icon.

    0 讨论(0)
提交回复
热议问题