Skip to content
This repository has been archived by the owner on Sep 4, 2020. It is now read-only.

push.setApplicationIconBadgeNumber not working in background #736

Closed
maikelsgit opened this issue Mar 22, 2016 · 4 comments
Closed

push.setApplicationIconBadgeNumber not working in background #736

maikelsgit opened this issue Mar 22, 2016 · 4 comments

Comments

@maikelsgit
Copy link

Expected Behaviour

When a push message is received override the badge count number with setApplicationIconBadgeNumber() when app is in background.

Actual Behaviour

When a push message is received when the app is in the background nothing happens, the badge number wil be the badge number that is included in the push payload. When the app is open it works.

Reproduce Scenario (including but not limited to)

Steps to Reproduce

Click app to the background and send a push notification. The app wil show the badge count number included in the push payload and ignores the push.setApplicationIconBadgeNumber function.

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

iOS 9.3

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

Cordova CLI version and cordova platform version

cordova --version                                #6.0.0
cordova platform version iOS                     #4.0.1

Plugin version

cordova plugin version | grep phonegap-plugin-push   #1.6.0

Sample Push Data Payload

{"aps":{"alert":"Testing.. (1)","badge":1,"sound":"default"}}

Sample Code that illustrates the problem

var push = PushNotification.init({ 
            "ios": {
                "alert": true, 
                "badge": true, 
                "sound": true, 
                "clearBadge": false 
            }

        });

push.on('notification', function(data) {
            console.log(data.count);
            push.setApplicationIconBadgeNumber(function() {
                console.log('success');
            }, function() {
                console.log('error');
            }, data.count + 1);
});

Logs taken while reproducing problem

When the app is running the log is showing me the data.count of the push payload, 1 in this case and it also shows ''succes".
When the app is in de background there are no logs shown.

@macdonst
Copy link
Member

@Jarvey you are not sending a background notification so your notification handler is not being run. Send this payload:

{"aps":{"alert":"Testing.. (1)","badge":1,"sound":"default", "content-available": 1}}

If that fixes the problem please close this issue.

@maikelsgit
Copy link
Author

@macdonst yes this fixed it, it is now working.

@alaa-alshamy
Copy link

@macdonst is there any thing like badge payload in android to update badge number from os?

because i need to update it even if the app is totally closed

@lock
Copy link

lock bot commented Jun 4, 2018

This thread has been automatically locked.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 4, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

3 participants