Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getToken() empty string #239

Open
theasmoth opened this issue Feb 3, 2017 · 6 comments
Open

getToken() empty string #239

theasmoth opened this issue Feb 3, 2017 · 6 comments

Comments

@theasmoth
Copy link

phonegap + plugin
getToken() callback with empty string
what im doing wrong?

document.addEventListener("deviceready", onDeviceReady, false);

var pushtoken;

function onDeviceReady() {
    console.log("device is ready");

    initFCM();
    getToken();
}


function initFCM() {
	 FCMPlugin.onTokenRefresh(function(token){
	 	pushtoken = token;
	 	console.log('onTokenRefresh:', token);
	 }, function(err){
	 	console.log('error retrieving token: ' + err);
	 });
	 FCMPlugin.onNotification(function(data){
	 	if(data.wasTapped){
	 		console.log(JSON.stringify(data));
	 	}else{
	 		console.log(JSON.stringify(data));
	 	}
	 }, function(msg){
	 	console.log('onNotification callback successfully registered: ' + msg);
	 }, function(err){
	 	console.log('Error registering onNotification callback: ' + err);
	 });
}
function getToken() {
	 FCMPlugin.getToken(function(token){
	 	pushtoken = token;
	 	console.log('getToken:', token);
	 	if (!token) setTimeout(getToken, 1000);
	 }, function(err){
	 	console.log('error retrieving token: ' + err);
	 });
}
@ole1986
Copy link

ole1986 commented Feb 8, 2017

I have the impression that some devices do not properly get the token.
Possible they have disable Push in through app manager?!

In order to get a new token, I always had to clear its application cache (through App Manager - android) . So that the onTokenRefresh event fires again

@frjufvjn
Copy link

Perhaps...
Console.log ('onTokenRefresh:', token);
Console.log ('onTokenRefresh:'+ token);
Please change to.

@woosungchu
Copy link

same issue and similar code.

console.log ...

FCMPlugin.js: is created
FCMPlugin Ready OK
device is ready
callback successfully registered: OK
getToken: 
getToken: 

cordova version 6.5.0
tested in

  • real device in android
  • emulator sdk-25 version

@woosungchu
Copy link

Problem sovled... in my case,

I think I should build once server with 'server key' provide by fcm then it knows app registered.
After I have built django app with serverkey once, token were sent to my android app.

@contactwahyu
Copy link

hi, could you please explain more details as I also having the same issues? the token is not coming...

@theasmoth
Copy link
Author

@contactwahyu use android emulator or xcode simulator
i faced this problem using NOX app player

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants