2016-07-24 5 views

답변

3

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); 
    }) 
); 
}); 
+0

약속의 notificationEvent 변수가 정의되지는 폐쇄되지 않는 이유 이잖아. 도와주세요!! – Supermacy

+0

대체 솔루션을 시도하십시오. – Marco

+0

Chrome 버전 59.0.3071.115 (공식 빌드) (64 비트) 두 번째 해결 방법이 이상하게 작동합니다. 서버에서 메시지를 푸시 할 때마다 기본 표시 알림이 표시됩니다 (이 사이트는 백그라운드에서 업데이트되었습니다). –

관련 문제