单击推送通知时打开应用程序

时间:2018-06-06 06:14:09

标签: java firebase ionic-framework push-notification ionic2

我有一个Ionic应用程序,通过FCM接收推送通知。问题是,当应用程序不在前台并且我点击状态栏上的通知时,应用程序将无法打开(尽管执行了来自(' notification')的操作) 。这是我的移动应用代码:

this.pushNotifications.on('notification').subscribe((data: any) => {
  if (data.additionalData.foreground) {
    alert('Ai primit un mesaj nou');
  }
  this.events.publish("gotMessage");
});

请注意this.events.publish("gotMessage");已执行。

这就是我通过Java发送通知的方式:

Map body = DataMap.map(
    "registration_ids", tokens,
    "data", DataMap.map(
        "content-available", "1",
        "title", "Fmcg Reporter",
        "body", "Ai primit un mesaj nou",
        "sound", "default"
    ),
    "collapse_key", "FmcgReporter"
);

Map headers = DataMap.map(
   "Authorization", "key=" + key,
   "Content-Type", "application/json"
);

Strings.readMethodURL("POST", "https://fcm.googleapis.com/fcm/send", headers, Strings.toJSON(body));

1 个答案:

答案 0 :(得分:0)

确保在使用服务器发送推送通知时指定“click_action”。下面是我的node.js服务器的一个工作示例:

// method: "POST",
//url: "https://fcm.googleapis.com/fcm/send",
    // get the key from Firebase console
    headers: { Authorization: `key=${fcmServerKey}` }, 
    json: {
        "notification": { 
            "title": "Message title",
            "body": "Message body",
            "click_action": "URL to your app?"
        },
        // userData is where your client stored the FCM token for the given user
        // it should be read from the database
        "to": userData.fcmRegistrationKey
    }