Ionic push for android errors

Hello. I am trying to get ionic push to work for gcm (android device) but cannot seem to get it work. BTW, I am using ionic very own push feature and got the dev mode ( dev_push: true) to work properly. But after following the instructions to set up using gcm, and passing in gcm_id in $ionicAppProvider, I got the following exception: (inspect thru chrome:inspect)

TypeError: Cannot read property ‘register’ of undefined
at Object.register (file:///android_asset/www/ng-cordova.js:5932:41)
at init (file:///android_asset/www/lib/ionic-service-push/ionic-push.js:125:20)
at file:///android_asset/www/lib/ionic-service-push/ionic-push.js:288:21

// app.js
$ionicAppProvider.identify({
app_id: ‘xxx’,
api_key: ‘xxx’,
gcm_id: ‘mygcm_id’
});

// my controller
$scope.identifyUser = function() {
var user = $ionicUser.get();

$ionicUser.identify(user).then(function(){
$scope.pushRegister();
});
};

// Registers a device for push notifications
$scope.pushRegister = function() {
$ionicPush.register({

onNotification: function(notification) {
return true;
}
});

Any pointers? I am running on actual android physical device and dev mode is working fine for me.

Thanks!

Same error here. Can’t find a solution.
I’ve tried to put the identifyUser call inside $ionicPlatform.ready with no luck.

Did you manage to make it work?

Same here, it does not work when I switch to real gcm_id on actual device even I can see the android device id on the push web control panel.

I also get the following error:

TypeError: Cannot read property 'pushNotification' of undefined at Object.register (ng-cordova.js:5932)

With dev_push: true it works.

Same problem. Any solution?

Same problem. Any solution?

Same problem. Any solution? (3)

Hi, I just getting working in android. I changed the ionic-service-push to 0.1.8.

bower uninstall ionic-service-push 
bower install ionic-service-push\#0.1.8

Just check if is included push in the index.html like:

<script src="lib/ionic-service-push/ionic-push.js"></script>

and also don’t forget configure app.js like (fill with the proper keys)

angular.module('starter', ['ionic','ionic.service.core','ionic.service.push','starter.controllers', 'starter.services', 'ngCordova',  ])
.config(['$ionicAppProvider', function($ionicAppProvider) {
 // Identify app
 $ionicAppProvider.identify({
   // The App ID (from apps.ionic.io) for the server
   app_id: '',
   // The public API key all services will use for this app
   api_key: '',
   // If true, will attempt to send development pushes
   dev_push: true,
   // The GCM project number
   gcm_id: ''
 });
}])
1 Like

Awesome! That helped.

I am running 1.13 and getting this bug, do I still need to revert to an older version or is this getting fixed

I am using 1.13 today and it works …

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);