morinel / gcmpush

Titanium Module for Android Push
Apache License 2.0
57 stars 35 forks source link

registerPush called twice #51

Open fadaytak opened 8 years ago

fadaytak commented 8 years ago

hello, im using SDK 5.4.0 GA and 1.7 version of the module

this is my code

var gcm = require("nl.vanvianen.android.gcm");

/* If the app is started or resumed act on pending data saved when the notification was received */
    var lastData = gcm.getLastData();
    if (lastData) {
        Ti.API.info("Last notification received " + JSON.stringify(lastData));
        gcm.clearLastData();
    }

    gcm.registerPush({
        senderId : 'XXXXXXXX',
        notificationSettings : {
            sound : '', /* Place sound file in platform/android/res/raw/mysound.mp3 */
            smallIcon : 'appicon.png', /* Place icon in platform/android/res/drawable/notification_icon.png */
            largeIcon : 'appicon.png', /* Same */
            vibrate : true, /* Whether the phone should vibrate */
            insistent : true, /* Whether the notification should be insistent */
            group : 'MyNotificationGroup', /* Name of group to group similar notifications together */
            localOnly : false, /* Whether this notification should be bridged to other devices */
            priority : +2, /* Notification priority, from -2 to +2 */
            bigText : true,
            /* You can also set a static value for title, message, or ticker. If you set a value here, the key will be ignored. */
            // title: '',
            // message: '',
            // ticker: ''
            /* Add LED flashing */
            ledOn : 200,
            ledOff : 300
        },
        success : function(event) {
            Ti.API.info("Push registration success: " + JSON.stringify(event));
            synchronize(event);
        },
        error : function(event) {
            Ti.API.error("Push registration error: " + JSON.stringify(event));
            alert("Fail to register for remote push notification");
        },
        callback : function(event) {
            Ti.API.info("Push callback = " + JSON.stringify(event));
            // Called when a notification is received and the app is in the foreground
            //TODO print message notification
            var dialog = Ti.UI.createAlertDialog({
                title : 'Push received',
                message : JSON.stringify(event.data),
                buttonNames : ['View', 'Cancel'],
                cancel : 1
            });
            dialog.addEventListener("click", function(event) {
                dialog.hide();
                if (event.index == 0) {
                    //Do stuff to view the notification
                }
            });
            dialog.show();
        }
    });

and i got a success registration and just after an error message

[INFO] :   Push registration success:     {"registrationId":"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX8ny0B0KQa9UrCn8s","success":true}

and just after

[ERROR] :  GCMIntentService: (IntentService[GCMIntentService--2]) [197,4105] Error: INVALID_SENDER
[ERROR] :  GCMModule: (IntentService[GCMIntentService--2]) [1,4106] INVALID_SENDER

something missing? im sure that im calling this library one time !

morinel commented 8 years ago

Are you sure you specified the correct senderId as obtained from Google's Developer console?

fadaytak commented 8 years ago

Yes and I got a correct registration id and juste after the error !!

I'm using it with alloy in a library but I'm sure that I'm calling the library one time

fahad86 commented 7 years ago

I too have seen concurrent modification errors on our servers at the API the endpoint which is used to save the device tokens obtained from successful registration. Highly likely that it is due t the duplicate registration reported.