Ionic Push not registering device tokens

Hi,
I am making an app where I want to use Ionic Push to send push notifications to all devices. The problem is, device tokens do not register, so I can not send push notifications. Here is my code.

app.js

var iosConfig = {
            'badge': true,
            'sound': true,
            'alert': true,
        };
        $ionicAppProvider.identify({
            app_id: '9a817ab5',
            api_key: 'ef581894f393b5ca0109017cd15355fb3ba03ea51aa53784',
            name: 'Lovett',
            // Set the app to use development pushes
            dev_push: false
        });

        $cordovaPush.register(iosConfig).then(function(result) {
            // Success -- send deviceToken to server, and store for future use
            console.log('result: ' + result)
            $rootScope.deviceToken = result;
            //$http.post('http://server.co/', {user: 'Bob', tokenID: result.deviceToken})
        }, function(err) {
            alert('Registration error: ' + err)
        });


        $rootScope.$on('$cordovaPush:notificationReceived', function(event, notification) {
            if (notification.alert) {
                navigator.notification.alert(notification.alert);
            }

            if (notification.sound) {
                var snd = new Media(event.sound);
                snd.play();
            }

            if (notification.badge) {
                $cordovaPush.setBadgeNumber(notification.badge).then(function(result) {
                    // Success!
                }, function(err) {
                    // An error occurred. Show a message to the user
                });
            }
        });

controllers.js

$scope.pushRegister = function() {
            console.log('Ionic Push: Registering user');

            // Register with the Ionic Push service.  All parameters are optional.
            $ionicPush.register({
                canShowconsole.log: true, //Can pushes show an console.log 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,
                onNotification: function(notification) {
                    // Handle new push notifications here
                    // console.log(notification);
                    return true;
                }
            }).then(function(result) {
                submitRegister();
                console.log('result: ' + result)
            });
        };
        var submitRegister = function() {
            console.log('Ionic Push: User registered');
            $scope.nextSlide();
        }
        $rootScope.$on('$cordovaPush:tokenReceived', function(event, data) {
            console.log("Successfully registered token " + data.token);
            console.log('Ionic Push: Got token ', data.token, data.platform);
            $scope.token = data.token;
        });
1 Like

I’m having a similar problem. Users are being identified, but no device tokens are stored. The image below comes from the Ionic users tab.

2 Likes

+1, Same issue with android push notifications

1 Like

I’m having the simmilar problem :confused:
pls any one can help us?

Yup Same,

checked http://docs.ionic.io/docs/push-faq#section-no-valid-device-tokens

but that doesn’t help either.

Have you installed bower?

npm install -g bower

For me it was the problem
after the bower install plz update the ionic core and push pluggin :

ionic add ionic-service-core
ionic add ionic-service-push

I hope that can help you

1 Like

@Remy1 Yes I did try that a while back to no avail. This time I tried using the Push starter app and following the directions outlined here.

I am now able to register device tokens, identify and register users for iOS but now sending pushes doesn’t work although their statuses indicate they have been sent successfully.

For instance I’ve sent a push to a device (my own) and here’s the message status:

I thought I should update everyone on the status of my push issues. I have decided not to use Ionic Push, but the Parse push service. It is based off of a REST API that is way easier than Ionic Push IMO.

2 Likes

I get DEV-numbers-numbers-numbers.
My device tokens are not showing in the users section either.
How did you get the real device token?

@andrewoodleyjr See the $cordovaPush plugin here to get the actual device token
http://ngcordova.com/docs/plugins/pushNotifications/

1 Like

@spivotron thanks for recommending the link.

Hi @spivotron,

I am having the same issues with Ionic Push, so I went down the Parse avenue as well. Or at least tried to.

Did you get any errors when you first tried Parse? My app crashes when running in Xcode and I get this message in my output:

*** Terminating app due to uncaught exception ‘NSInternalInconsistencyException’, reason: ‘Could not load NIB in bundle: ‘NSBundle </private/var/mobile/Containers/Bundle/Application/0E835245-160B-4FAD-9D86-90DFAE9E1B9C/UBA Expo.app> (loaded)’ with name ‘ViewController’’

Does anyone know what this means? I have Googled this for the past few days, but I am not getting a clear answer.

@mmilligan Fortunately I did not have any issues with trying Parse. It looks like your code is trying to execute something but failed because it hasn’t been handled properly. You might not have initialized parse correctly.

I used the Javascript SDK from Parse for web. First include this in your index.html file: <script src="//www.parsecdn.com/js/parse-1.5.0.min.js"></script>
Then include this in your app.js: Parse.initialize("APP_ID", "JAVASCRIPT_ID");

I found my problem! I forgot to set my AppID and Client Key inside of my AppDelegate.m file. Once I did that, my app started without a hiccup.

Thanks for letting me know about Parse 1.5.0. I’m not sure if it would of been a huge issue, but I was running off an older version :stuck_out_tongue:

1 Like

+1, Same issue with IOS push notifications

Also, I’m saw Error message “TypeError: Cannot read property ‘pushNotification’ of undefined” when using code below

$cordovaPush.register({
badge: true,
sound: true,
alert: true
}).then(function (result) {

}, function (err) {
console.log(‘reg device error’, err);
});

Any word on this? It appears to be working in simulator (assigns device token) but not in production?

It’s resolved with me.

Can you refer at link: https://github.com/hollyschinsky/PushNotificationSample
and IonicPush: I can't push notification when outside the app

Have a nice day :smile:

I had also this problem, and i resolved checking the inclusion of ‘lib/ionic-service-push/ionic-push.js’ on index.html , which was missing.

Sometimes 'ionic plugin add ’ doesn’t do the trick.

This is how I got GCM working. It’s fairly simple and straightforward.

The ng-cordova plugin on their website is deprecated. You should use this one: GitHub - phonegap/phonegap-plugin-push: Register and receive push notifications

To get the device to register the device you’ve got to use a listener to wait until the device is ready:

var push = PushNotification.init({
“android”: {
“senderID”: “your-GCM-key”,
“icon”: “letters”,
“forceShow”: “true”},
“ios”: {
“sound”: “true”
},
“windows”: {}
} );
document.addEventListener(“deviceready”, function(){
push.on(‘registration’, function(data) {
Data.saveUserToken(data.registrationId);
});

Some other things you need to look out for are that the plugin WILL NOT work in the browser. You have to install it on a device. It will not register a browser and you WILL get the “TypeError: Cannot read property ‘pushNotification’ of undefined” in the browser, but on a device it works fine. Note: If you’re using the ionic push you should be able to do testing in the browser. Lastly, make sure you include ng-cordova BEFORE cordova.

1 Like

I solved using the Ionic.io instead the Angular integration.
First remember to use ionic-platform-web-client instead of ionic-service-push , which is deprecated (see at https://github.com/driftyco/ionic-service-push-client)

Run:

ionic add ionic-platform-web-client

Then, for production:

ionic config set dev_push false

This is my code:

Ionic.io();
var push = new Ionic.Push();
var user = Ionic.User.current();
    
// if the user doesn't have an id, you'll need to give it one.
if (!user.id) {
  user.id = Ionic.User.anonymousId();
}
 
user.set('name', $rootScope.user_name);
user.set('bio', $rootScope.user_bio);
user.save();
    		
 var callback = function(data) {
   console.log('Registered token:', data.token);
   console.log(data.token);
   push.addTokenToUser(user);
   user.save();
}
push.register(callback);
4 Likes