$ionicPush.register() return differents tokens for a same $ionicUser


#1

Hello,

When I use $ionicUser.identify( device.uuid ), the device.uuid is always the same, but each time I launch the app, $ionicPush.register() return a different push token ( iOS or Android ).

I suppose it’s not the expected behaviour ?

Or, may be each time the token change and we need to update it on our server side to use the last one generated ?

Thanks for your help.


#2

Could you post your code? I get the same token each time.


#3

Ok, thanks for your answer, so this confirm it’s not the expected result :slight_smile:

Here is my code:

var pushSetup = function()
{
    if (!window.hasOwnProperty('device')) {
        c.log(t(), 'push setup waiting device plugin...');
        return $timeout(pushSetup, 100);
    }
    if (!$ionicUser) {
        c.log(t(), 'push setup waiting $ionicUser plugin...');
        return $timeout(pushSetup, 100);
    }
    if (!$ionicPush) {
        c.log(t(), 'push setup waiting $ionicPush plugin...');
        return $timeout(pushSetup, 100);
    }
    c.log(t(), 'push setup...', $ionicPush, $ionicUser);
    var pushDevice = $ionicUser.get();
    if (!pushDevice.user_id) {
        pushDevice.user_id = device.uuid;
    }
    angular.extend(pushDevice,
    {
        build:      config.build,
        os:          device.os,
        osVersion: device.osVersion,
    });
    $ionicUser.identify(pushDevice).then(function()
    {
        c.log(t(), 'ionic device identified ' + pushDevice.user_id);
        $ionicPush.register({
            canShowAlert:       true,
            canSetBadge:        true,
            canPlaySound:       true,
            canRunActionsOnWake:true,
            onNotification: function(notification)
            {
                c.log(t(), 'NOTIFICATION',  notification);
                return true;
            }
        });
    });
    $rootScope.$on('$cordovaPush:tokenReceived',
    function(event, data)
    {
        c.log(t(), 'TOKEN REGISTERED ' + data.token, event, data);
    });
};
pushSetup();

This code is in my ng-controller of the first state loaded ( running before $ionicReady, this is why I’m waiting if necessary that the $ionicPush / $ionicUser object exists )

Thanks for your help @Kaptajnen


#4

@ericb explained me on Gitter that behaviour is expected in dev_push mode.

So, this should not be here when I’ll switch dev_push to false.

Thanks !


#5

Sorry I didn’t get back to you earlier. I can confirm that you get a unique token in production but not in dev_mode