ionic-team / ng-cordova

OBSOLETE: Please move to Ionic Native https://github.com/ionic-team/ionic-native
https://github.com/ionic-team/ionic-native
MIT License
3.48k stars 1.05k forks source link

Push notifications don't work on Andnroid Marshmellow #1199

Open Zeladgolan opened 8 years ago

Zeladgolan commented 8 years ago

When upgrading to the new Android version suddenly the push notifications weren't received.

gortok commented 8 years ago

Could be an issue in the underlying plugin and not the wrapper. Which push plugin wrapper are you using? And are there any open issues on the Cordova plugin page about Marshmellow?

Zeladgolan commented 8 years ago

This is wrapper I've used. http://ngcordova.com/docs/plugins/pushNotifications/

vitaliy-bobrov commented 8 years ago

@Zeladgolan You should use $cordovaPushV5 for notifications, because previous version is deprecated. Look at available methods here https://github.com/driftyco/ng-cordova/blob/master/src/plugins/push_v5.js

Zeladgolan commented 8 years ago

Thanks @vitaliy-bobrov, Should I just replace the js file or install the whole plugin? cordova plugin rm cordova new_plugin add?

bestmazzo commented 8 years ago

@Zeladgolan here a bit of tested code:

angular.module('myApp', ['ngCordova'])
        .run(function ($cordovaPushV5) {
            var pushConfig = {
                android: {
                    senderID: "_YOUR_ID_"
                },
                ios: {
                    alert: "true",
                    badge: "true",
                    sound: "true"
                },
                windows: {}
            };
            document.addEventListener("deviceready", function () {
                $cordovaPushV5.initialize(pushConfig)
                        .then(function (push) {
                            push.on('notification', function (notification) {
                                // WHAT TO DO ON PUSH NOTIFICATION?
                                // CHANGE FOLLOWING CODE ACCORDING TO YOUR NEEDS
                                alert(JSON.stringify(notification));
                            });
                        });
                   $cordovaPushV5.register().then(function (result) {
                    // Success
                    alert("Successfully registered for PUSH NOTIFICATION: " + result);
                }, function (err) {
                    // Error
                    alert("Error registering for PUSH NOTIFICATION: " + err);
                });
            });

        });