我正在使用FCM插件为ion2推送通知。 参考:https://www.npmjs.com/package/cordova-plugin-fcm使用FCM保存设备令牌在离子2中
我跟着https://github.com/edismooth/ionic2-firebase/tree/master
它工作正常,我可以从火力控制台收到推送。现在我想构建自己的服务器,让管理员通过自己的后端发送推送通知。
我面临的一个问题是:我可以获取设备令牌,但是,我不知道如何将其保存到本地存储。代码如下。我可否知道我错了哪一部分? “this.local.set”不能在“FCMPlugin.getToken”的功能中使用。如果是,我如何保存令牌并使用此功能?非常感谢。
initializeApp() {
this.platform.ready().then(() => {
StatusBar.styleDefault();
FCMPlugin.getToken(
function (token) {
console.log(token); //I can get the token data
this.local.set('tokenvalue', token); // the token value can't be saved to local storage like this
},
function (err) {
console.log('error retrieving token: ' + err);
}
);
}
的可能的复制[离子2 - 如何存储全局变量(http://stackoverflow.com/questions/41103557/ionic-2-how-to-store-global-variable) – Matt