0

I’m trying to develop Firebase - Push Notifications with Framework7. I have installed the plugin by checking $ cordova plugin list cordova-plugin-fcm 2.1.2 “FCMPlugin” I have registered the app on the Firebase Console and have no idea whether this code is correct or not (it’s inside the app.js)

onDeviceReady: function() {
// JScript for the main app, once PGap has loaded.
//checkDeviceSize(); (WILL RE-CODE IN A CSS FRIENDLY FORMAT)
document.addEventListener(“offline”, onOffline, false);
document.addEventListener(“online”, onOnline, false);
setTimeout(function() {
navigator.splashscreen.hide();
}, 1000);

var pushtoken;

initFCM();
getToken();

},

then, at the bottom of file app.js, I put the function

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);
 });
}
}

Would be very grateful if you can show how to manage this code inside app.js Many thanks

0 Answers0