简体   繁体   English

使用离子推送的多个推送通知

[英]Multiple push notifications using ionic push

When sending two notifications the second one always overrides the first one in the notification center. 发送两个通知时,第二个通知始终会覆盖通知中心中的第一个通知。 According to the docs this should happen only when using the tag: 根据文档,这应该仅在使用标记时发生:

"tag": Indicates whether each notification message results in a new entry on the notification center. “标签”:指示每个通知消息是否会在通知中心上产生一个新条目。 If not set, each request creates a new notification. 如果未设置,则每个请求都会创建一个新通知。 If set, and a notification with the same tag is already being shown, the new notification replaces the existing one. 如果已设置,并且已经显示具有相同标签的通知,则新通知将替换现有通知。

However this happens to me all the time, regardless whether I set a value for the tag or not. 但是,无论我是否为标签设置值,这种情况一直在我身上发生。

I even tried setting a random tag & collapse_key (which as far I understand shouldn't be related in this case, but I gave it a try). 我什至尝试设置一个随机标签和crash_key(据我所知,在这种情况下不应该将其关联,但我尝试了一下)。 Still didn't help. 仍然没有帮助。 Here's a sample of a notification object I'm sending: 这是我要发送的通知对象的示例:

{  
   "tokens":[  
      "my-device-token"
   ],
   "profile":"my-profile-tag",
   "notification":{  
      "message":"message",
      "android":{  
         "payload":{  
            "collapse_key":9918519,
            "tag":2825928
         }
      }
   }
}

I resolved this problem. 我解决了这个问题。 You need to add "notId" into "data" in "android". 您需要在“ android”的“ data”中添加“ notId”。 Example: 例:

"notification": {
    "title": "testing stack notification ",
    "message":"is it working",
    "android": {               
        "data": {
            "title": "testing stack notification",
            "message": "is it working",
            "style": "inbox",
            "summaryText": "yes its %n% notifications",
            "notId": "123456"
        }
    }
}

You need to specify a unique notification id (unix timestamp for example) in the object in order not to overwrite the previous one - in your case: 您需要在对象中指定一个唯一的通知ID(例如,unix时间戳),以免覆盖前一个-在您的情况下:

{  
   "tokens":[  
      "my-device-token"
   ],
   "profile":"my-profile-tag",
   "notification":{  
      "notId": <some-unique-value-here>,
      "message":"message",
      "android":{  
         "payload":{  
            "collapse_key":9918519,
            "tag":2825928
         }
      }
   }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM