fechanique / cordova-plugin-fcm

Google FCM Push Notifications Cordova Plugin
623 stars 998 forks source link

getToken() empty string #239

Open theasmoth opened 7 years ago

theasmoth commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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

woosungchu commented 7 years ago

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

woosungchu commented 7 years ago

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 commented 5 years ago

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

theasmoth commented 5 years ago

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