PushManager

Push APIPushManager 인터페이스는 서드파티 서버에서 알림을 수신하거나, URL에 푸시 알림을 요청하는 방법을 제공합니다.

PushManagerServiceWorkerRegistration.pushManager (en-US) 속성으로 접근할 수 있습니다.

속성

PushManager.supportedContentEncodings (en-US)

푸시 메시지의 페이로드를 암호화할 때 지원하는 콘텐츠 인코딩의 목록을 반환합니다.

메서드

PushManager.getSubscription() (en-US)

기존의 푸시 구독을 가져옵니다. 해당 구독에 대한 상세 정보를 담은 PushSubscription (en-US) 객체를 Promise로 반환합니다. 구독이 존재하지 않으면 프로미스는 null로 이행합니다.

PushManager.permissionState() (en-US)

PushManager의 허가 상태로 이행하는 Promise를 반환합니다. 상태는 'granted', 'denied', 'prompt' 중 하나입니다.

PushManager.subscribe() (en-US)

푸시 서비스에 구독합니다. 해당 구독에 대한 상세 정보를 담은 PushSubscription (en-US) 객체를 Promise로 반환합니다. 현재 서비스 워커에 이전 구독이 존재하지 않으면 새로운 푸시 구독을 생성합니다.

Deprecated methods

PushManager.hasPermission() (en-US) 지원이 중단되었습니다

Returns a Promise that resolves to the PushPermissionStatus of the requesting webapp, which will be one of granted, denied, or default. Replaced by PushManager.permissionState() (en-US).

PushManager.register() (en-US) 지원이 중단되었습니다

Subscribes to a push subscription. Replaced by PushManager.subscribe() (en-US).

PushManager.registrations() (en-US) 지원이 중단되었습니다

Retrieves existing push subscriptions. Replaced by PushManager.getSubscription() (en-US).

PushManager.unregister() (en-US) 지원이 중단되었습니다

Unregisters and deletes a specified subscription endpoint. In the updated API, a subscription is unregistered by calling the PushSubscription.unsubscribe() (en-US) method.

예제

this.onpush = function(event) {
  console.log(event.data);
  // From here we can write the data to IndexedDB, send it to any open
  // windows, display a notification, etc.
}

navigator.serviceWorker.register('serviceworker.js').then(
  function(serviceWorkerRegistration) {
    serviceWorkerRegistration.pushManager.subscribe().then(
      function(pushSubscription) {
        console.log(pushSubscription.endpoint);
        // The push subscription details needed by the application
        // server are now available, and can be sent to it using,
        // for example, an XMLHttpRequest.
      }, function(error) {
        // During development it often helps to log errors to the
        // console. In a production environment it might make sense to
        // also report information about errors back to the
        // application server.
        console.log(error);
      }
    );
  });

명세

Specification
Push API
# pushmanager-interface

브라우저 호환성

BCD tables only load in the browser

같이 보기