电容器无法接收android特定的推送通知

时间:2019-05-03 09:26:59

标签: android firebase-cloud-messaging ionic4 capacitor

我尝试为我的Ionic4-Capacitor-App实现推送通知。

在应用程序中,我有以下代码:

PushNotifications.register();
PushNotifications.createChannel({ id: '1', description: '2019', importance: 2, name: '2019'});
PushNotifications.addListener('pushNotificationReceived', (notification) => {
    console.debug(JSON.stringify(notification));
});

我尝试使用POSTMAN发送以下消息:

{
    "to": "<User-Token>",
    "notification": {
        "title": "Default Title",
        "body": "Default Body"
    },
    "android": {
        "notification": {
            "title": "Android Title",
            "body": "Android Title",
            "channel_id": "1"
        }
    }
}

Here is the documentation I used.

我收到的通知的标题为“默认标题”,正文为“默认正文”。 我希望它具有“ Android标题”和“ Android正文”。此外,通知不会推送到频道1,而是会推送到其他。

当我忽略“根”通知部分时,根本没有显示通知。

1 个答案:

答案 0 :(得分:0)

对于面临相同问题的每个人: 这是我为通过Postman发送Firebase云消息而进行的配置步骤。

Google-Cloud配置:

  1. 转到:https://console.cloud.google.com/apis/credentials/consent
  2. 将getpostman.com添加到授权域中
  3. 转到:https://console.cloud.google.com/apis/credentials
  4. 添加新的OAuth-Client-ID
  5. 选择Web应用程序并为其命名。
  6. 将授权的重定向URL设置为https://www.getpostman.com/oauth2/callback并保存。
  7. 为此帐户下载Json

POSTMAN配置:

  1. 将请求类型设置为POST
  2. 输入网址:https://fcm.googleapis.com/v1/projects/ {您的firebase-project-name} / messages:send
  3. 转到“授权”,选择OAuth 2.0类型,然后单击“获取新访问令牌”
  4. 授予类型的授权码
  5. 回调URL:https://www.getpostman.com/oauth2/callback
  6. 验证URL:[json文件中的auth_uri]
  7. 访问令牌URL:[json文件中的token_uri]
  8. 客户端ID:[json文件中的client_id]
  9. 客户端机密:[来自json文件的client_secret]
  10. 范围:https://www.googleapis.com/auth/firebase.messaging
  11. 状态:[空]
  12. 客户端身份验证:作为基本身份验证标头发送

完成这些步骤后,您应该能够按照本文档中的说明发送消息:https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages/send