Issues with $cordovaPush


#1

We’re trying to use cordova push with google cloud messaging for android devices. We’re testing on two devices, an s6 and s3. Both are getting registration ids correctly. The s6 is receiving messages while the app is in the foreground, but no alerts are appearing in the status bar while the app is in the background or not started. The s3 doesn’t receive any messages at all. In all cases gcm is returning a success code for the messages.

Relevent code below:

document.addEventListener("deviceready", function() {
    var androidConfig = {
        "senderID": "<snip>",
    };
    
    // register the device 
    $cordovaPush.register(androidConfig).then(function(result) {
        LocationService.debug_messages.push({ message: 'device has been registered! ' + result, timestamp: new Date().getTime() });
    }, function(err) {
        LocationService.debug_messages.push({ message: 'device failed to register ' + err, timestamp: new Date().getTime() });
    });

    $rootScope.$on('$cordovaPush:notificationReceived', function(event, notification) {
        switch(notification.event) {
            case 'registered':
                if (notification.regid.length > 0 )
                    LocationService.debug_messages.push({ message: 'device registered with token: ' + notification.regid, timestamp: new Date().getTime() });
                    
                    try
                    {
                        var device_registration = $firebaseArray(FirebaseFactory.child('user_devices/' + self.auth.uid));
                        
                        device_registration.$add({
                            token: notification.regid,
                            type: 'android'
                        }).then(function (ref) {
                            // set local storage for the device to store the token firebase reference
                            localStorage.setItem("device_push_token_" + self.auth.uid, ref.key());
                            
                            LocationService.debug_messages.push({ message: 'user device token saved to firebase: ' + ref.key(), timestamp: new Date().getTime() });
                        }).catch(function (error) {
                            LocationService.debug_messages.push({ message: 'error saving regid to firebase: ' + error, timestamp: new Date().getTime() });
                        });
                    } catch (ex) {
                        LocationService.debug_messages.push({ message: 'exception saving regid to firebase: ' + exception, timestamp: new Date().getTime() });
                    };
                    
                break;

            // this is the actual push notification. its format depends on the data model from the push server
            case 'message':
                LocationService.debug_messages.push({ message: 'message = ' + notification.message + ' msgCount = ' + notification.msgcnt, timestamp: new Date().getTime() });
                break;

            case 'error':
                LocationService.debug_messages.push({ message: 'device push notification error ' + notification.msg, timestamp: new Date().getTime() });
                break;

            default:
                LocationService.debug_messages.push({ message: 'An unknown push notification GCM event has occurred', timestamp: new Date().getTime() });
                break;
        }
    });
}, false);