Skip to content
This repository has been archived by the owner on Sep 4, 2020. It is now read-only.

"push.unregister" not really work in iOS #296

Closed
bau720123 opened this issue Nov 3, 2015 · 7 comments
Closed

"push.unregister" not really work in iOS #296

bau720123 opened this issue Nov 3, 2015 · 7 comments
Labels

Comments

@bau720123
Copy link

hi @macdonst
I am using PGB cli-5.2.0 with your 1.4.1 verison (Android 4.4.2 and iOS 9.1[13B143])
these are my prosedure

step 1

push.on('registration', function(data)
{
alert(data.registrationId);
});

step 2

push.unregister(successHandler, errorHandler);

function successHandler(result)
{
alert(result);
}

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

well...
when in Android,step 1 will get a "data.registrationId",after it I execute step 2,and execute step 1 again,it will get a "new and different" value
but when in iOS,step 1 will get a "data.registrationId",after it I execute step 2,and execute step 1 again,it still get a "same" value just like step 1

the "successHandler" will all trigger success
is the iOS have a different behavior than Android ?

@macdonst macdonst added the retest label Nov 3, 2015
@fredgalvao
Copy link
Collaborator

I believe that's the expected behaviour, now that this plugin uses instance-id. A new one will be generated everytime the cicle completes (register -> unregister -> re-register).

@bau720123
Copy link
Author

hi @fredgalvao
thanks your reply
I am a little confuse
so you mean is...
for now the conclusions are as follows

in iOS,after unregister and re-register,still get a same data.registrationId is a expected behaviour
in Android,after unregister and re-register,will get a different data.registrationId is a expected behaviour
right ?

if yes,why Android have no this behavior just like the iOS ?

@adyz
Copy link

adyz commented Nov 4, 2015

In my android, I get the same registrationId and therefor no notifications...

Update: Looks like I get different id in in 1.4.2 -- I was using 1.4.0

@bau720123
Copy link
Author

yes @adyz
this is waht I mean

@fredgalvao
Copy link
Collaborator

iOS links the registrationId to a combination of factors as to my experience, such as provisioningProfile used and deviceUUID, so that if you complete the re-registering cycle, you'll get the same registrationId (neither provisioning profiles nor deviceUUIDs have changed, so that's expected).

The case with Android is different now, because this plugin is using instance-id as of 1.4.0. Google docs specify that instance-id's have a shorter scope, and can (will) be renewed from time to time, depending on a few possible events (server refresh, callback cleanup, maintenance, etc). Triggering an unregister tells google that the previously valid instance-id is now free to fly, and it will be discarded. When you re-register, a new one (and different too) will be provided.

The recommendation here is that you talk to your server everytime the registration event triggers with a new or different value, so that your server always has a list of valid registrationIds. For a cleaner approach, you can even link the registrationId to your account identifier (if your app has the concept of an user account) or to the device UUID if you need a cheap and quick solution. That way, you'll always have a most recent pair of UUID+registrationID for a certain UUID, and that is the registrationId you should use to target notifications to that user/device.

Something along the lines:

push.on('registration', function(data) {
    if (data.registrationId !== previousRegistrationIdPersistedSomewhere) {
        var params = {uuid: device.uuid, registrationId: data.registrationId};
        $.get('http://url.to.my.server/updateRegistrationIdForACertainUUID', params);
    }
})
def updateRegistrationIdForACertainUUID(String uuid, String registrationId) {
    def pr = PushRegistration.findByUuid(uuid)

    if (pr && pr.registrationId != registrationId) {
        /* I need to update it */
        pr.registrationId = registrationId
        pr.save()
    } else if (!pr) {
        /* I need to create it */
        pr = new PushRegistration(uuid: uuid, registrationId: registrationId)
        pr.save()
    }
}

@bau720123
Copy link
Author

thanks @fredgalvao
very clear and totally know what are you talking about
close it

@lock
Copy link

lock bot commented Jun 5, 2018

This thread has been automatically locked.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 5, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

4 participants