PushSubscription: unsubscribe() 메서드

Baseline 2023

Newly available

Since March 2023, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.

Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

참고: 이 기능은 Web Worker에서 사용할 수 있습니다.

PushSubscription 인터페이스의 unsubscribe() 메서드는 현재 구독이 성공적으로 구독 취소될 때 불리언 값으로 이행되는 Promise를 반환합니다.

구문

js
unsubscribe()

매개변수

없음.

반환 값

현재 구독이 성공적으로 구독 취소될 때 불리언 값으로 이행되는 Promise.

예제

js
navigator.serviceWorker.ready.then((reg) => {
  reg.pushManager.getSubscription().then((subscription) => {
    subscription
      .unsubscribe()
      .then((successful) => {
        // 성공적으로 구독을 취소했습니다
      })
      .catch((e) => {
        // 구독 취소에 실패했습니다
      });
  });
});

명세서

Specification
Push API
# dom-pushsubscription-unsubscribe

브라우저 호환성

BCD tables only load in the browser

같이 보기