Identify users / generate token for Ionic.io Push

Hi Guys,

I have an inherited Ionic framework app that is using Ionic.io
The app authorises against our API, and is given an API token to use in future requests.

I’m trying to work on push notifications - I’ve set up ionic push, and can trigger push notifications out to all users with no problems.

I’d like the ability to target specific users / devices to send notifications, and I understand that to do this, I have to register the device to generate a token.

Within my $ionicPlatform.ready function, I have:

    $ionicPush.register().then(function(t) {
        return $ionicPush.saveToken(t);
    }).then(function(t) {
      console.log('Token saved:', t.token);
    });

This however does not seem to be returning a token, and calling

console.log($ionicPush);

Shows that the token is not set.

Any ideas here? What am I missing?

have you added [‘ionic.cloud’] dependency

So after digging though some documentation, I found that the issue was linked with the ionic user.

In the main run function, I fire off a

if ($ionicAuth.isAuthenticated()) {
If this fails, I try a login of a user, and a register of the user if appropriate. (user is already logged in using a custom auth token against our api)

Before I attempt to register the token, I then have to reload the user in order to have the app save off and push back up to ionic.io.

 $ionicUser.load().then(function() {
    $ionicPush.register().then(function(t) {
        console.log('Token sent:', t.token);
        return $ionicPush.saveToken(t);
    }).then(function(t) {
      console.log('Token saved:', t.token);
    });
});