phonegap / phonegap-plugin-push

Register and receive push notifications
MIT License
1.94k stars 1.91k forks source link

iOS badge not updated when app is in **foreground** #2282

Open peterlauri opened 6 years ago

peterlauri commented 6 years ago

Expected Behaviour

When application is in foreground and push with badge count only is received the badge icon should update.

Actual Behaviour

When application is in foreground and push with badge count only is received the badge icon is not updated.

Reproduce Scenario (including but not limited to)

App in foreground

Steps to Reproduce

Have app in background, send push with badge=100, badge=100 Enter app (foreground), send push with badge=10, put app in background... badge is 100, and not 10.

Platform and Version (eg. Android 5.0 or iOS 9.2.1)

iOS=11.2.6

(Android) What device vendor (e.g. Samsung, HTC, Sony...)

Cordova CLI version and cordova platform version

cordova --version = 8.0.0
cordova platform version ios = 4.5.4

Plugin version

cordova plugin version | grep phonegap-plugin-push

2.2.2

Sample Push Data Payload

Sample Code that illustrates the problem

Logs taken while reproducing problem

WORKAROUND with cordova-plugin-badge

          push.on('notification', (data) => {
            // TODO: this is a workaround to update the badge when in foreground
            if (data && data.additionalData && data.additionalData.foreground && data.count != undefined) {
              cordova.plugins.notification.badge.set(data.count);
            }
          });
macdonst commented 6 years ago

@pataar huh, that's weird as the OS should take care of the badge. Can you give me a full example of your push payload?

pataar commented 6 years ago

Hi @macdonst, I think you mentioned the wrong person haha.

macdonst commented 6 years ago

@pataar I sure did.

@peterlauri huh, that's weird as the OS should take care of the badge. Can you give me a full example of your push payload?

peterlauri commented 6 years ago

@macdonst you refer to the payload sent to FCM or the payload received by the plugin?

macdonst commented 6 years ago

@peterlauri the one sent to FCM

peterlauri commented 6 years ago

@macdonst here you go. I removed some private information.

{
  "android": {
    "priority": "high"
  },
  "data": {
    "somedatakey": "participant_read_message"
  },
  "notification": {
    "badge": 0
  },
  "to": "XXX"
}
stale[bot] commented 6 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

macdonst commented 6 years ago

@peterlauri sorry, been busy but I believe this is a bug in the push implementation. It seems like we should be setting

[UIApplication sharedApplication].applicationIconBadgeNumber=[[userInfo objectForKey:@"aps"] valueForKey:@"badge"];

in this if https://github.com/phonegap/phonegap-plugin-push/blob/14afb94126acb51a6f10a2094f7f391f2f17dee5/src/ios/AppDelegate%2Bnotification.m#L111