1
1 분 후에 푸시 알림을 숨겨야합니다. 이를 위해 내 서비스 직원이 무엇을해야합니까?잠시 후 푸시 알림을 숨기는 방법은 무엇입니까?
1 분 후에 푸시 알림을 숨겨야합니다. 이를 위해 내 서비스 직원이 무엇을해야합니까?잠시 후 푸시 알림을 숨기는 방법은 무엇입니까?
Notification.close() method을 사용할 수 있습니다. ServiceWorkerRegistration.showNotification에 의해 반환 된 약속이 해결되는 NotificationEvent 개체를 사용하여 알림에 링크 된 Notification 개체를 가져올 수 있습니다. 이 같은
뭔가 :
self.addEventListener('push', event => {
event.waitUntil(
self.registration.showNotification('Title', {
body: 'Body.',
})
.then(notificationEvent => {
let notification = notificationEvent.notification;
setTimeout(() => notification.close(), 60000);
})
);
});
또 다른 가능한 솔루션은 ServiceWorkerRegistration.getNotifications로 표시하고 모든 알림을받을 것입니다. 예를 들어
:
self.addEventListener('push', event => {
event.waitUntil(
self.registration.showNotification('Title', {
body: 'Body.',
})
.then(() => self.registration.getNotifications())
.then(notifications => {
setTimeout(() => notifications.forEach(notification => notification.close()), 60000);
})
);
});
약속의 notificationEvent 변수가 정의되지는 폐쇄되지 않는 이유 이잖아. 도와주세요!! – Supermacy
대체 솔루션을 시도하십시오. – Marco
Chrome 버전 59.0.3071.115 (공식 빌드) (64 비트) 두 번째 해결 방법이 이상하게 작동합니다. 서버에서 메시지를 푸시 할 때마다 기본 표시 알림이 표시됩니다 (이 사이트는 백그라운드에서 업데이트되었습니다). –