phonegap-build / PushPlugin

This repository is deprecated head to phonegap/phonegap-push-plugin
https://github.com/phonegap/phonegap-plugin-push
MIT License
1.32k stars 1k forks source link

Unregister does not work #669

Open Nett opened 8 years ago

Nett commented 8 years ago

Hello,

I need to run unregister on login, to prevent receiveing push notification assigned to previous user.

As I know GCM chains all registrationID's, and if I call "unregister" it should break that chain and when I register again GCM will create new one registrationID not related to previous.

For example:

I login with user1 and send to him notification, it works fine. Then I logout and login with user2, here in unregister success calback I call register function to get new registrationId for user2. And when I send notification to user1 (whose regID should become invalid after unregister) anyway my device receives notification.

Could you please advice? Maybe I'm doing something wrong.

I know that it's not recommended to user unregister method.

But how can I check if notification is not related to current client? I have only "onMessage" callback, and is there a way to catch notification event before it appears in notification center? I can send whatever data to identify is current notification related to this client. And also how can I reject this notification if it's not related to this user?

Here is the code sample with unregistration usage:

function registerGcmNotifications (senderId) { var pushNotification = window.plugins.pushNotification;

try {   
    pushNotification.unregister(
        function(res){
        alert("UNREGISTER SUCCESS");
            pushNotification.register(
                function onSuccessRegister (result) {
                alert("NEW REGISTER SUCCESS");
                    // alert("Success register: " + JSON.stringify(result))
                },
                function onErrorRegister (error) {
                    // alert("Error register: " + JSON.stringify(error))
                },
                {
                    "senderID": senderId,
                    "ecb": "onNotificationGCM"
                }
            );
        }, 
        function(err) {

        }
    );
} catch (e) {
    alert("GCM registration failed")
    return
}

}