使用推送通知Ionic 4的FCM

时间:2019-08-20 10:40:52

标签: ionic-framework ionic4

FCM使用推送通知离子4 enter image description here

我也附上了我的错误日志,

我已安装https://ionicframework.com/docs/native/fcm

我正在使用离子cli --- 4.12.0

I am trying to send push notification on my device with the help of FCM 

和离子4。但是我无法获得令牌。我正在获取iOS的设备令牌 并且我已经导入了 app.module.ts app.component.ts aslo, 我已尝试将令牌存储在本地存储中,但即时通讯获取了空值 我在想念吗?

 initializeApp() {
this.platform.ready().then(() => {
  this.statusBar.styleLightContent();
  this.splashScreen.hide();
  this.fcm.subscribeToTopic('marketing');


  //Receving
  this.fcm.getToken().then((token) => {
    localStorage.setItem('token', token);
  }, (err) => {
    alert(JSON.stringify(err));
  });


  this.fcm.onNotification().subscribe((data) => {
    console.log("Data :", data);
    if (data.wasTapped) {
      console.log("Received in background " + JSON.stringify(data));
      alert("Received in background " + JSON.stringify(data));
    } else {
      console.log("Received in foreground" + JSON.stringify(data));
      alert("Received in foreground" + JSON.stringify(data));
    }
  });
  //Updating
  this.fcm.onTokenRefresh().subscribe((token) => {

    localStorage.setItem('token', token);
    console.log(token);
    alert('refresh token: ' + token);
  });

  this.fcm.unsubscribeFromTopic('marketing');

});

}

0 个答案:

没有答案