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