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.

We’d love to hear your thoughts on the next set of proposals for the JavaScript language. You can find a description of the proposals here.
Please take two minutes to fill out our short survey.

보안 컨텍스트: 이 기능은 일부 또는 모든 지원 브라우저보안 컨텍스트 (HTTPS)에서만 사용할 수 있습니다.

참고 : 이 기능은 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

브라우저 호환성

같이 보기