【发布时间】:2019-10-03 01:37:59
【问题描述】:
从我试图完成它的几天开始,但我完全被困在这一点上。
这是我的 service worker 文件中的代码
importScripts('https://www.gstatic.com/firebasejs/6.0.2/firebase-app.js');
importScripts('https://www.gstatic.com/firebasejs/6.0.2/firebase-messaging.js');
firebase.initializeApp({
messagingSenderId: "xxxxxxxxxxxx"
});
var messaging = firebase.messaging();
messaging.setBackgroundMessageHandler(function(payload) {
console.log('[firebase-messaging-sw.js] Received background message ', payload);
// Customize notification here
var notificationTitle = payload.data.title; //or payload.notification or whatever your payload is
var notificationOptions = {
body: payload.data.body,
icon: payload.data.icon,
image: payload.data.image,
data: { url:payload.data.openURL }, //the url which we gonna use later
actions: [{action: "open_url", title: "View"}]
};
return event.waitUntil(self.registration.showNotification(notificationTitle,
notificationOptions));
});
self.addEventListener('notificationclick', function(event) {
console.log('event = ',event);
event.notification.close();
event.waitUntil(clients.openWindow(event.notification.data.url));
switch(event.action){
case 'open_url':
window.open(event.notification.data.url);
break;
case 'any_other_action':
window.open(event.notification.data.url);
break;
}
}, false);
数据就是这种格式
$data=[
'title' => 'message title',
'body' => 'description body',
'icon' => 'https://i.ytimg.com/vi/gXSyP9ga-ag/hqdefault.jpg',
'image'=>'https://i.ytimg.com/vi/gXSyP9ga-ag/mqdefault.jpg',
'openURL'=>'https://google.com'
];
现在有很多问题。
在手机上点击推送通知正文时,不会打开url,只会关闭它(只有点击动作按钮会打开链接
-
我在网上看了一些,发现
event.waitUntil(clients.openWindow(event.notification.data.url));不适用于 safari 和 safari iPhone,谁能帮我找到 了解如何实现一个可以与苹果一起使用的点击甚至监听器 设备?
任何帮助将不胜感激
【问题讨论】:
标签: javascript firebase push-notification firebase-cloud-messaging service-worker