Ionic-Push: No device tokens

Hello,

My code: https://gist.github.com/jprangenberg/171bc6bad0834d20d44a

The creation of an ionic user works fine. But the user have no device token. The ‘tokenReceived’ callback function is not called.

Help! Thanks.

Hey!

The code you posted looks good, as far as registering for push notifications goes, so it’s probably something else preventing you from getting a token. There’s probably some useful errors being logged when you attempt to register and I’d be able to help more specifically if I could see those, but here’s a couple thoughts off the top of my head:

  • Are you running this in a browser, or on a physical device? Native push notifications won’t work in a browser, an emulator, or with Ionic View. You can get around this with the dev_push mode for testing, which can be enabled by running ionic config set dev_push true in the root of your project directory. More docs on this here
  • If you’re on iOS, you may have misconfigured your provisioning profile, which Xcode will use to sign your app. This can cause the registration to fail with an error along the lines of no valid 'aps entitlement' string, or something to that effect.
  • Of you’re on Android, the most likely cause is an incorrect GCM senderID. This ID is your Google app’s project number, and is set with ionic set gcm_key <your-sender-id>

Hey fuiste,

thanks for your fast reply.

  1. I’m running my app on an android device.
  2. Should i call ionic set gcm_key <your-sender-id>? Should i do this once?
    I have configurate the gcm_key with following code:
    https://gist.github.com/jprangenberg/0c7f11b4f2979ba2a682

Thank you!

Hey fuiste,

it doesn’t work. I have done all things again.

I doesn’t get an ionic user with device tokens. What is going wrong here?

I have the same problem (native Android device):

  • identification of a user works fine
  • when registering the user, i receive “REGISTERED OK” - but no token is shown in the dashboard

Same problem here. GCM key, APP_ID and Secret is set correctly, and user identification works fine.

The console log of REGISTERED OK shows my token, but when I look in ionic users there is no token available.

Hello momsenmeister, hello alex77,

i have solved my issue!

Old code: https://gist.github.com/jprangenberg/171bc6bad0834d20d44a
New code: https://gist.github.com/jprangenberg/5c6822c76b28f0f63d56

It seems also to be important to install following ngCordova plugin: http://ngcordova.com/docs/plugins/pushNotifications/

I hope that fix your problems.

Hello jprangenberg,

I don’t really understand your changes, where do you execute $ionicPush.identify()…?

Hello momsenmeister,

i don’t call identify direct. On line 25, i send data of the user to identify him. Take a look at
the ‘register’ function of ionic push.

https://gist.github.com/jprangenberg/5c6822c76b28f0f63d56#file-pushv2-js-L25

Important: install ngCordova module “pushNotifications”: http://ngcordova.com/docs/plugins/pushNotifications/

Still can’t get it working :frowning:
All works fine with dev notifications, but on my device I just can’t get a token.
This listener is never called, and the ionic dashboard shows “No Android device tokens for this user”.

$rootScope.$on('$cordovaPush:tokenReceived', function(event, data) {
    alert("Successfully registered token " + data.token);
    console.log('Ionic Push: Got token ', data.token, data.platform);
    $scope.token = data.token;
});

Any more ideas?

I’ve tried all this - still the same problem; no device tokens in dashboard. Here’s my code in case it helps:

$scope.login = function(form) {
	AuthService.login($scope.user).then(function(response) {

		// register device for push
		$ionicPush.register({
			canShowAlert: false,
			canSetBadge: true,
			canPlaySound: true,
			canRunActionsOnWake: true,
			onNotification: function(notification) {
				alert(JSON.stringify(notification));
				return true;
			}
		}, {
			user_id: response.puserId
		});

		var user = $ionicUser.get();

		// Metadata
		_.extend(user, {
			username: $scope.user.username
		});

		$state.go('app.beacons');
	}, function(error) {
		UIService.showAlert({
			title: 'Oops!',
			template: error
		})
	})
}

$scope.logout = function(form) {
	$rootScope.currentUser = null
	$state.go('login');
}

// Handles incoming device tokens
$rootScope.$on('$cordovaPush:tokenReceived', function(event, data) {
	console.log('Ionic Push: Got token ', data.token, data.platform);
	$scope.token = data.token;
});

Do you have installed the ngCordova module “pushNotifications”?

Finally solved it by just updating ionic to 1.1.0 and the plugins accordingly.
The code was fine all the time :stuck_out_tongue_closed_eyes:
So, anyone who still has issues - make sure to update all your dependencies first!!!

Can you tell the others, how you update all your dependencies?

Check Plugin IOS

AppDelegate+notification.h
AppDelegate+notification.m
PushPlugin.h
PushPlugin.m

Add a reference for this plugin to the plugins section in config.xml:

<feature name="PushPlugin">
  <param name="android-package" value="com.plugin.gcm.PushPlugin" />
  <param name="ios-package" value="PushPlugin" />
</feature>

Hello,
Same issue as described. Real device right data and that even worked a month ago. Then without changing any code I see that

$rootScope.$on('$cordovaPush:tokenReceived', function(event, data) {

callback is not called now.

Updated to ionic 1.1.0
Checked push plugin installed.
Updated config.xml with name=“PushPlugin” section.

jprangenberg, don’t see your github pages, can you bring thm\em back?

3 Likes