【发布时间】:2018-02-13 07:04:19
【问题描述】:
今天 (13.02.2018) 我的产品无法正常工作。我正在使用它们来通知有关公司门户服务台中的来电和应用程序的通知。 我按标签对通知进行了明确分类。所以我在 serviceworker 中收到通知:
self.addEventListener('push', function(event) {
event.waitUntil(
self.registration.pushManager.getSubscription().then(function(subscription) {
if(event.data.json().notification.tag == 'Asterisk_Incomming'){
if(typeof(event.data.json().data) == "undefined"){
return NotifyIncomming(event.data.json());
}else {
return NotifyIncommingCall(event.data.json());
}
}else if(event.data.json().notification.tag == 'Asterisk_Queue'){
return NotifyIncomming(event.data.json());
}else if(event.data.json().notification.tag == 'Assistant_Notify'){
return NotifyIncomming(event.data.json());
}else if((event.data.json().notification.tag == 'Helpdesk_Notify') || (event.data.json().notification.tag == 'Helpdesk_Notify_Tech')){
return NotifyHelpdesk(event.data.json());
}else{
return NotifyIncomming(event.data.json());
}
})
.catch(function(err) {
console.error('Невозможно получить данные с сервера: ', err);
})
);
});
在活动内部,我可以得到event.data.json()中的数据
我需要 2 个对象:data、notification
以前,通知对象包含标签参数,我得到它为event.data.json().notification.tag
但是现在标签包含在数据中(引用对象的全部内容):
{gcm.notification.tag: "Helpdesk_Notify", channel: "36840"}
但第一个对象引用无效。这是一个错误还是不断变化?如何从数据中获取标签?
即我以以下形式将 JSON 发送到 https://fcm.googleapis.com/fcm/send(使用授权令牌):
{
"notification":{
"body":"Статус заявки: ВЫПОЛНЕНА",
"icon":"images/ManageEngine.jpg",
"tag":"Helpdesk_Notify",
"title":"Ваша заявка обновлена"
},
"data":{
"channel":"36840"
},
"registration_ids": ["c4CfPHwLp7s:APA91bG3sf-0ua1RlhkcnTb6xuUWB46rg-grtdPfUYF7Ji8aw2awKTgRAoTP3CAiL-Fyjqk6FbwxOElV6qN8JQZIqLusiDed77OatEzj4Ae-hs3021wt2_gi4AeiRRnl3y6ToPBPY6em"]
}
截至 2018 年 2 月 13 日
我收到了notification in
链接:event.data.json().notification
表格:{title: "Ваша заявка обновлена", body: "Статус заявки: ВЫПОЛНЕНА", icon: "images/ManageEngine.jpg", tag: "Helpdesk_Notify"}
我收到了data
链接:event.data.json().data
表格:{channel: "36840"}
2018 年 2 月 13 日之后
我收到了notification in
表格:{title: "Ваша заявка обновлена", body: "Статус заявки: ВЫПОЛНЕНА", icon: "images/ManageEngine.jpg"}
我收到了data
表格:{gcm.notification.tag: "Helpdesk_Notify", channel: "36840"}
我可以将标签作为附加参数传递给数据,但我不喜欢这个选项。
【问题讨论】:
标签: javascript firebase web firebase-cloud-messaging service-worker