Ionic Push: Cannot read property 'register' of undefined


#1

Hello !

I’m trying to use the Ionic Push service.
I have followed the documentation, but I have an error when I’m trying to use the $ionicPush.register() function.

The $ionicPush.register() function exists, I’m sure because I show it’s typeof just before calling it.
So, the problem seems to be inside the $ionicPush.register() function :

TypeError: Cannot read property 'register' of undefined
    at Object.register (ng-cordova.js:6362)
    at init (ionic-push.js:125)
    at ionic-push.js:288
    at new Q (ionic.bundle.js:22259)
    at Q (ionic.bundle.js:22246)
    at Object.register (ionic-push.js:249)
    at taxi.pro.js:335
    at processQueue (ionic.bundle.js:22016)
    at ionic.bundle.js:22032
    at Scope.$eval (ionic.bundle.js:23228)

Here is my js/app.js :

.config(function($ionicConfigProvider, $ionicAppProvider)
{   
    $ionicAppProvider.identify({
        app_id:     config.ionicID,
        app_key:    config.ionicKey,
        gcm_id:     config.gcmID,
    });
});

( all config.* values are correctly set )

And in my appController ( with $ionicUser, $ionicPush, $rootScope in function parameters ) :

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
    });
    $ionicUser.identify(pushDevice).then(function()
    {   
        c.log(t(), 'ionic device identified ' + pushDevice.user_id);
 
    c.log(t(), '' + (typeof $ionicPush.register));
    c.log(t(), $ionicPush.register ? 'exist' : 'not exist');
    $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();

The device is correctly identified, but this break just inside the $ionicPush.register function…
Any help will be appreciated :slight_smile:
I precise I have added ionic plugins and added JS scripts in index.html

Ionic v1.6.1
Cordova 5.1.1
CrossWalk 14.42.343.17

% ionic list
Ions, bower components, or addons installed: 
ionic
ionic-service-core
ngCordova
ionic-service-push

Thanks !


#2

Solved. Missing field ‘dev_push’ parameter !