Skip to content

Push Notification : ecb function executes for first time only. #1

Description

@joshilomas

Hi,
I am trying to develop android app using PhoneGap and AngularJS. Push notifications are working good but the only problem is that the ecb function executes for the first time of the compilation. I have alert text inside ecb function. I got the push notifications on notification bar but on clicking them doesn't call ecb funciton, only app starts.
After i restart the app, although app is running , i got the notification in notification bar and ecb function is not working.
Please help me..
I have posted my sample code related to GCM: Push notification

.factory('GCM', ["$window", "$rootScope", function ($window, $rootScope){

    function registerGCM(){
        var pushNotification;
        pushNotification = window.plugins.pushNotification;
        pushNotification.register(
        successHandler,
        errorHandler, {
            "senderID":"676655225205",
            "ecb":"onNotificationGCM"
        });

    }

    function successHandler(result){
         //alert('result = ' + result);
    }

    function errorHandler(error){
        alert(error);   
    }

    $window.onNotificationGCM = function (e){
        switch(e.event){
            case 'registered':
                if ( e.regid.length > 0 )
                {
                    $rootScope.$broadcast('reg_key', e.regid);
                }
                break;

            case 'message':
                alert('ecb function is called');
                break;

            case 'error':
                alert('GCM error = '+e.msg);
                break;

            default:
                alert('An unknown GCM event has occurred');
                break;
        }
        return true;
    }

    return{
        register: function(){
            return registerGCM();
        }           
    };
}]);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions