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
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: ''
});
}])
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);