【问题标题】:Open app when clicking push notification单击推送通知时打开应用程序
【发布时间】:2018-06-06 06:14:09
【问题描述】:

我有一个 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));

【问题讨论】:

  • 什么是设备平台-android?
  • 您是否尝试将“click_action”添加到您的“数据”obj 中?
  • 是的,我用的是安卓

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


【解决方案1】:

确保在使用服务器发送推送通知时指定“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
    }

【讨论】:

  • 对我不起作用。或者,也许我在“click_action”中添加了一些错误的东西。我已经从 config.xml 添加了我的 ap id。我在哪里可以找到应用程序的网址?
  • 嗨,Alex,您的应用安装在真实设备上对吗?您将需要为 url 添加和使用特殊模式。我看看能不能找到
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多