首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >点击推送通知时打开app

点击推送通知时打开app
EN

Stack Overflow用户
提问于 2018-06-06 14:14:09
回答 1查看 592关注 0票数 0

我有一个离子应用程序,通过FCM接收推送通知。问题是,当应用程序不在前台时,当我点击状态栏上的通知时,应用程序不会打开(尽管执行了从on (‘通知’)开始的操作)。这是我的移动应用代码:

代码语言:javascript
复制
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发送通知的方式:

代码语言:javascript
复制
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));
EN

回答 1

Stack Overflow用户

发布于 2018-06-07 07:06:08

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

代码语言:javascript
复制
// 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
    }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50713302

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档