[SOLVED] Framework 7 & Cordova-plugin-fcm (iOS)

var app = new Framework7({
  root: '#app',
  theme: 'ios',
  tapHold: true,
  pushState: true,
  domCache: true,
    swipeout: {
    noFollow: true,
    removeElements: false,
  },
  init: false,
  on: {
    init: function () {
      setTimeout(gethetok, 20000);

      function gethetok() {
      FCMPlugin.getToken(function(token) {
        localStorage.fcmtok=token;
        console.log(token);
        if (token===null) {
          console.log('asdsadsa');
        }
        FCMPlugin.onNotification(function(data) {
            console.log(data);
            if (data.wasTapped) {
      
               alert(JSON.stringify(data));
          } else {
       
           alert(JSON.stringify(data));
             }
        });
    });
  }
 }

When I test my app in XCode I can receive the Instance Id from Firebase after some seconds (that’s why I have include “setTimeout(gethetok, 20000);” ). I have done all the steps right (include GoogleService-info.plist etc.). I have tested this token via console and I can receive the notification. My problem is that I cannot store via localStorage the value (Instance Id). Am I doing something wrong?

// set
localStorage.setItem('myToken','_token_');

// get
var tkn=localStorage.getItem('myToken');

// delete
localStorage.removeItem('myToken');

// clear all items
localStorage.clear();

I have tried that too, I think that the plugin doesn’t run. Is this the place that I should add?
I have tried:
`document.addEventListener(“deviceready”, onDeviceReady, false);
function onDeviceReady() {
FCMPlugin.onTokenResfresh(function (token) {
if (token == null) {
localStorage.fcmtok=0;
console.log(“null token”);
} else {
console.log(token);
localStorage.fcmtok=token;
FCMPlugin.onNotification(function(data) {
console.log(data);

       if (data.wasTapped) {
      //     //Notification was received on device tray and tapped by the user.
         alert(JSON.stringify(data));
      } else {
      //     //Notification was received in foreground. Maybe the user needs to be notified.
         alert(JSON.stringify(data));
      }
  });

}

},
function (err) {
console.log('error retrieving token: ’ + err);
}
);
}
`
instead of:
on: {
init: function () {
setTimeout(gethetok, 20000);

      function gethetok() {
      FCMPlugin.getToken(function(token) {
        localStorage.fcmtok=token;
        console.log(token);
        if (token===null) {
          console.log('asdsadsa');
        }
        FCMPlugin.onNotification(function(data) {
            console.log(data);
            if (data.wasTapped) {
      
               alert(JSON.stringify(data));
          } else {
       
           alert(JSON.stringify(data));
             }
        });
    });
  }
 }

and nothing happened.

hi, just curious, why you need to wait 20s? are you listening for deviceready event?
i use phonegap-plugin-push

          push.on('notification', function (data) {
            console.log(data)
            // alert('Event=notification, message=' + data.message)
          });

and i get the token almos instantly.

I think the plugin is not running because I can see “FCMPlugin is not declared etc.” in safari debug mode. Is this the right way to call a plugin in framework7?

I tried to include the code under #login button but I get -> undefined is not a function (near ‘…FCMPlugin.getToken…’)

SOLVED! I add Cordova.js in head and works!

I would suggest to wait for deviceready event. Instead of moving cordova.js to head. This way you know that cordova has loaded and you can use your plugins.

Hi, where we can put this function? in app.js or other js file?
Thanks in advance

What is domCache in app config?

you mean in app.js? strangely there is no domCache, what is the default value?

No domCache in app config: https://github.com/framework7io/framework7/search?q=domCache&unscoped_q=domCache