【问题标题】:ionic - firebase push only work with opened app?ionic - firebase push 仅适用于打开的应用程序?
【发布时间】:2020-05-21 20:11:40
【问题描述】:

我在 Ionic 4 应用中实现了 FireBaseX 以发送远程通知。

this.platform.ready().then(() => {
  let platforms = this.platform.platforms();

  if(platforms.includes('ios') || platforms.includes('android') || platforms.includes('mobile')){

    this.firebase.getToken().then(token => {
      console.log(`FIREBASE TOKEN ${token}`);
      if(platforms.includes('ios')) this.firebase.grantPermission();
    });

    this.firebase.onMessageReceived().subscribe(data => {
      console.log('FIREBASE MESSAGE', data);
    });

  }

});

所以当我在 iOS 中打开应用时,它会正确请求权限。

然后我发送测试消息,console.log() 正确显示。

2020-02-05 17:35:38.282123-0300 Parkaz[86464:2354851] didReceiveMessage: {
    "collapse_key" = "com.myapp.app";
    from = 678323471xxxx;
    notification =     {
        body = teste;
        e = 1;
        tag = "campaign_collapse_key_5659280550157990837";
        title = teste;
    };
}

但是,如果应用程序未打开,则不会发生任何事情。通知横幅没有出现,没有徽章,没有声音……什么都没有……

我做错了吗?

【问题讨论】:

    标签: firebase cordova ionic-framework


    【解决方案1】:

    您可以使用邮递员测试您的通知。

    POST : https://fcm.googleapis.com/fcm/send
    

    标题

    Content-Type:application/json
    Authorization:key=AIzaXXXXXXXXXX
    

    身体

    安卓

    { 
       "notification": {
          "title": "Your Notification Title", 
          "body": "This is Message",
       },
       "to" : FIREBASE TOKEN,
       "data": { 
          "content-available": 1,
          "foreground": false,
          "clickAction": "/chat"
       }
    }
    

    iOS

    { 
       "to" : FIREBASE TOKEN,
       "data": {
          "title": "Your Notification Title", 
          "body": "This is Message",
          "content-available": 1,
          "foreground": false,
       }
    }
    

    【讨论】:

    • 仍然是相同的结果...消息已发送,但仅在打开应用程序时才会显示在设备中
    【解决方案2】:

    通过将苹果 APNS 证书添加到 Firebase 设置面板来解决。

    【讨论】:

      猜你喜欢
      • 2015-07-29
      • 2016-04-22
      • 2013-10-26
      • 1970-01-01
      • 1970-01-01
      • 2015-06-20
      • 2021-03-10
      • 1970-01-01
      相关资源
      最近更新 更多