$ionicPush.register() not returning token


#1

I’m really hoping someone can help me, this has been driving me nuts. I’m trying to migrate my existing Ionic 1 project over to utilize the new Ionic Cloud Push functionality. I’ve followed the instructions very carefully, multiple times, but can’t get the push notifications to work. The docs are not clear - is a user required to authenticate using Ionic Cloud User Authentication for Push Notifications to work?

Here is my current set up. Please let me know if you would like me to paste in additional code or clarify any particulars as to my set up.

  1. I created an Ionic Cloud services account and logged in. I then followed all the steps on the http://docs.ionic.io/setup.html page. I’ve never had any problem using Promises so I skipped the bluebird step.

  2. I then created an app id using “ionic io init”.

  3. Added “ionic.cloud” to my app.js
    Here’s the pertinent section of my config:
    .config([’$ionicCloudProvider’,function($ionicCloudProvider){
    $ionicCloudProvider.init({
    “core”: {
    “app_id”: “MY APP ID”
    },
    “push”: {
    “sender_id”: “MY PERSONAL SENDERID”,
    “pluginConfig”: {
    “ios”:{
    “badge”: true,
    “sound”: true
    },
    “android” : {
    “iconColor”: “#343434
    }
    }
    }
    });

I’ve checked both the app_id and sender_id several times to make sure they’re correct.

  1. I followed the migration doc very carefully http://docs.ionic.io/migration.html

  2. I added the $ionicPush.register() promise to my controller:

    .controller(‘DashCtrl’, [’$ionicPush’, ‘$ionicPlatform’, function($ionicPush, $ionicPlatform){
    $ionicPlatform.ready(function(){
    $ionicPush.register().then(function(t){
    return $ionicPush.saveToken(t);
    }).then(function(t){
    console.log("Token saved: " + t.token);
    });
    });

  3. Token never arrives. I send a push notification and it never arrives to my device when I build && run on my Android phone.

What am I doing wrong? Should I move the $ionicPush.register() promise into the .run? Is anyone else having problems? Thanks in advance!


#2

Hi, ladragoon,

Did you found the solution for this? I had the same issue.


#3

Hi @ladragoon, @jueyuansanqv

i was struggling with this as well. What finally worked out was the following setup:

in .run-block i am first calling $ionicUser to register the current user as online. After that, i register for $ionicPush to receive the token. Finally i save the token if promise resolved successfully.

.run(function ($log, $ionicPlatform, $ionicPush, $ionicUser) {

      $ionicPlatform.ready(function () {
        // ANYTHING NATIVE **MUST** GO HERE

        // Get ionic user data
        $ionicUser.load().then(function() {

          // then register for push notifications to receive unique token
          $ionicPush.register({
            canShowAlert: true,         //Can pushes show an alert on your screen?
            canSetBadge: true,          //Can pushes update app icon badges?
            canPlaySound: true,         //Can notifications play a sound?
            canRunActionsOnWake: true,  //Can run actions outside the app,
          }).then(function(token) {
            return $ionicPush.saveToken(token);
          });

        });
});

If this is also not working for you, consider creating a debug-page within your application. There you can add buttons for testing push registration.

I hope this helps :slight_smile:


#4

Hey dotzilla,

Thank you so much for posting this! I’m going to try your suggestions/fix! Again, my thanks, I really appreciate it!


#5

Hi, I just figure out, that the reason why my push.register method never been fire up because of the error of “push plugin not found”.

Still no idea why i got this error, I’ve already install the plugin for android.

I also try to out the push.register method in run or in my login controller, but the error result shows different, in run, it said: push plugin not found. But in my login controller, it said: another registration in progress.

Any idea? Also, do you run it in browser or device?

Thanks.


#6

Hey Jueyuansanqv,

I’m giving dotzilla’s suggested fix a shot today, haven’t gotten as far as you yet. To answer your last question, I believe it can only run correctly in the actual device.


#7

hi,
@dotzilla @ladragoon
i found this: Problems with the Push Plugin (Error: Push plugin not found! See logs.), so it mean when we call the push out side of the platform.ready, it may coz the push plugin not out found error.

And now I’m trying to use the ionicUser and save the token to loaded ionicUser, but when i check in ionic.io, there’s no token for the user.