我正在使用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