fechanique / cordova-plugin-fcm

Google FCM Push Notifications Cordova Plugin
624 stars 990 forks source link

getToken return empty string/ null #569

Open contactwahyu opened 5 years ago

contactwahyu commented 5 years ago

Hi, I'm developing Framework7 and having this issue while trying to call getToken() Here is the code:

// Handle Cordova Device Ready Event $$(document).on('deviceready', function() { app.dialog.alert("Loading..."); //console.log("Device is ready!");

var pushtoken;

initFCM();
getToken();

});

function initFCM() {
    console.log("initializing...");
    if(typeof(FCMPlugin) != 'undefined') {
     FCMPlugin.onTokenRefresh(function(token){
        pushtoken = token;
        app.dialog.alert('onTokenRefresh:', token);
     }, function(err){
        app.dialog.alert('error retrieving token: ' + err);
     });
     FCMPlugin.onNotification(function(data){
        if(data.wasTapped){
            app.dialog.alert(JSON.stringify(data));
        }else{
            app.dialog.alert(JSON.stringify(data));
        }
     }, function(msg){
        app.dialog.alert('onNotification callback successfully registered: ' + msg);
     }, function(err){
        app.dialog.alert('Error registering onNotification callback: ' + err);
     });
     }
}
function getToken() {
    if(typeof(FCMPlugin) != 'undefined') {
     FCMPlugin.getToken(function(token){
        pushtoken = token;
        app.dialog.alert('getToken:', token);
        if (!token) setTimeout(getToken, 1000);
     }, function(err){
        app.dialog.alert('error retrieving token: ' + err);
     });
    }
}

When I call initFCM() I got this message : onNotification callback successfully registered: OK and after that I don't receive any token.

Kindly advise, many thanks before!

ghost commented 5 years ago

same here

sgadekar81 commented 5 years ago

Same happened with me, GoogleService-Info.plist was missing, so I added it at the root of my project and every thing started to work..