푸시 알림을 보내고 있습니다. 페이지를 등록한 다음 컬링 테스트를 통해 알림을 받았습니다.Chrome의 service-worker.js를 통해 24 시간 내 알림을받습니다.
그러나 푸시 알림 범위가 등록 된 탭을 닫은 후 잠시 (아마도 1 ~ 2 분), 알림을 다시 테스트하면 알림을받을 수 없습니다. 이것은 일반적으로 휴대 전화의 Chrome에서 더 많이 발생합니다.
내가 여기서 한 해결 방법은 범위가 지정된 페이지의 페이지로 이동해야한다는 것입니다. 그러면 알림을 다시 테스트 할 때 작동합니다. 비록 내가 클라이언트가 사이트에 항상 존재하지 않고 알림을받을 필요가 있기 때문에 내가 이것을 가질 수는 없지만. 여기
내가 SW의 등록의 범위의 페이지에없는이 있어도self.addEventListener('push', function(event) {
var SOME_API_ENDPOINT = "https://somewhre.com/push_notification_api/service_worker_endpoint";
event.waitUntil(
fetch(SOME_API_ENDPOINT, {
method: 'post',
headers: {
"Content-type": "application/x-www-form-urlencoded; charset=UTF-8"
},
body: 'subscription_id=' + subscriptionId
}).then(function(response) {
return response.json().then(function(data) {
var title = data.notification.title;
var message = data.notification.message;
var icon = base + "assets/images/logo_notification.png";
var notificationTag = data.notification.url;
// var notificationTag = 'https://google.com'; //data.notification.tag;
return self.registration.showNotification(title, {
body: message,
icon: icon,
tag: notificationTag
});
});
})
);
});
어떻게 내가 내 서비스 노동자 24을해야합니까 서비스 작업자 내 푸시 이벤트입니까?
eventListeners 'install', 'activate'및 'fetch'를 사용해야합니까?