# 웹 푸시 알림 사용자 동의 관리

기본적으로 Pushwoosh SDK 는 초기화되는 즉시 기본 구독 프롬프트를 표시합니다. 하지만 사용자가 웹사이트와 상호작용할 기회를 가진 후와 같이 더 적절한 시기에 사용자 동의를 요청하고 싶을 수 있습니다.

### 자동 구독 비활성화

SDK 가 초기화 시 구독 프롬프트를 자동으로 표시하는 것을 방지하려면 `init` 호출에서 `communicationEnabled` 매개변수를 `false` 로 설정합니다. 이렇게 하면 푸시 알림 권한을 요청할 시기를 제어할 수 있습니다.

```html
<script type="text/javascript" src="//cdn.pushwoosh.com/webpush/v3/pushwoosh-web-notifications.js" async></script>
<script type="text/javascript">
  var Pushwoosh = Pushwoosh || [];
  Pushwoosh.push(['init', {
    // other initialization parameters...
    communicationEnabled: false, // Disable communication to prevent automatic subscription prompts
  }]);
</script>
```

### 사용자 동의 시 구독 활성화

자동 구독을 비활성화한 후에는 언제든지 사용자에게 구독을 요청할 수 있습니다. 사용자가 푸시 알림 수신에 동의하면 (예: 사용자 지정 UI 의 "구독" 버튼을 클릭하여) `setCommunicationEnabled` 메서드를 호출하여 통신을 활성화할 수 있습니다.

`Pushwoosh.setCommunicationEnabled(status?: boolean): Promise<void>`

`Pushwoosh.setCommunicationEnabled(true)` 를 호출하면 Pushwoosh 서비스와의 통신이 활성화됩니다. 활성화되면 SDK 는 기본 브라우저 권한 프롬프트를 표시합니다.

이 메서드를 사용하는 방법의 예시는 다음과 같습니다:

```javascript
// Assuming you have a subscribe button with id="subscribe-button"
const subscribeButton = document.getElementById('subscribe-button');

subscribeButton.addEventListener('click', () => {
  Pushwoosh.setCommunicationEnabled(true)
    .then(() => {
      console.log('User is subscribed to push notifications.');
      // You can hide the subscribe button now
      subscribeButton.style.display = 'none';
    })
    .catch((error) => {
      console.error('Error subscribing user:', error);
    });
});
```