![](/img/trans.png)
[英]how to open url on click push notification when app is not working in background
[英]Open app when clicking push notification
我有一個Ionic應用程序,可通過FCM接收推送通知。 問題是,當應用程序不在前台並且我單擊狀態欄上的通知時,該應用程序將無法打開(盡管已執行on('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));
確保在使用服務器發送推送通知時指定“ 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
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.