# Managing user consent

Pushwoosh supports compliance with privacy regulations (e.g., GDPR, CCPA) by allowing developers to control when the SDK begins communication with Pushwoosh servers. This helps ensure that no data is collected before the user gives explicit consent.

### Overview

By default, the Pushwoosh SDK begins communication and collecting device data immediately upon initialization. However, you can change this behavior so that no communication happens until the user gives consent.

With this setup:

* If the user gives consent, the SDK initializes and begins collecting data.

* If the user does not give consent, the SDK stays inactive and does not collect any data.

* If the user later withdraws consent, the SDK stops all activity and disconnects from the servers.


Pushwoosh provides mechanisms to manage this flow in iOS, Android, and Unity.

### iOS

#### Disable SDK server communication at startup

By default, the communication with the SDK is enabled. To disable all communication with Pushwoosh servers until consent is explicitly granted by the user, add the following key to your **`Info.plist`**:

```xml
<key>Pushwoosh_ALLOW_SERVER_COMMUNICATION</key>
<false/>

```

#### Check communication status

Use the following methods to determine if communication is currently allowed:

<Tabs>
<TabItem label="SwiftUI">

```swift
import SwiftUI
import PushwooshFramework

var serverCommunicationAllowed = PWCoreServerCommunicationManager.sharedInstance.isServerCommunicationAllowed
print("isServerCommunicationAllowed: ", serverCommunicationAllowed)
```
</TabItem>
<TabItem label="Swift">

```swift
import PushwooshFramework

var serverCommunicationAllowed = PWCoreServerCommunicationManager.sharedInstance.isServerCommunicationAllowed
print("isServerCommunicationAllowed: ", serverCommunicationAllowed)
```
</TabItem>
<TabItem label="Objective-C">

```objective-c
#import <PushwooshFramework/PushwooshFramework.h>

BOOL serverCommunicationAllowed = [PWCoreServerCommunicationManager sharedInstance].isServerCommunicationAllowed;
NSLog(@"isServerCommunicationAllowed: %d", serverCommunicationAllowed);
```
</TabItem>
</Tabs>

#### Enable SDK communication after consent

Once the user has granted consent, enable communication as follows:

<Tabs>
<TabItem label="SwiftUI">

```swift
import SwiftUI
import PushwooshFramework

Pushwoosh.sharedInstance().startServerCommunication()
```
</TabItem>
<TabItem label="Swift">

```swift
import PushwooshFramework

Pushwoosh.sharedInstance().startServerCommunication()
```
</TabItem>
<TabItem label="Objective-C">

```objective-c
#import <PushwooshFramework/PushwooshFramework.h>

[[Pushwoosh sharedInstance] startServerCommunication];
```
</TabItem>
</Tabs>

#### Register for push notifications

Once communication is enabled, explicitly register for push notifications:

<Tabs>
<TabItem label="SwiftUI">

```swift
import SwiftUI
import PushwooshFramework

Pushwoosh.sharedInstance().registerForPushNotifications()
```
</TabItem>
<TabItem label="Swift">

```swift
import PushwooshFramework

Pushwoosh.sharedInstance().registerForPushNotifications()
```
</TabItem>
<TabItem label="Objective-C">

```objective-c
#import <PushwooshFramework/PushwooshFramework.h>

[[Pushwoosh sharedInstance] registerForPushNotifications];
```
</TabItem>
</Tabs>

#### Disable communication

To stop communication with Pushwoosh servers (e.g., if the user revokes consent):

<Tabs>
<TabItem label="SwiftUI">

```swift
import SwiftUI
import PushwooshFramework

Pushwoosh.sharedInstance().stopServerCommunication()
```
</TabItem>
<TabItem label="Swift">

```swift
import PushwooshFramework

Pushwoosh.sharedInstance().stopServerCommunication()
```
</TabItem>
<TabItem label="Objective-C">

```objective-c
#import <PushwooshFramework/PushwooshFramework.h>

[[Pushwoosh sharedInstance] stopServerCommunication];
```
</TabItem>
</Tabs>

### Android

#### Disable SDK server communication at startup

By default, communication is enabled. To prevent any data from being sent to Pushwoosh servers until user consent is obtained, add the following to your `AndroidManifest.xml`:

```xml
<meta-data
  android:name="com.pushwoosh.allow_server_communication"
  android:value="false" />
```

#### Check communication status

Use the following methods to determine if server communication is currently allowed:

<Tabs>
<TabItem label="Java">

```java
import com.pushwoosh.Pushwoosh;

boolean isCommunicationEnabled = Pushwoosh.getInstance().isServerCommunicationAllowed();
Log.d("Pushwoosh", "Communication enabled = " + isCommunicationEnabled);
```
</TabItem>
<TabItem label="Kotlin">

```kotlin
import com.pushwoosh.Pushwoosh

val isCommunicationEnabled = Pushwoosh.getInstance().isServerCommunicationAllowed()
Log.d("Pushwoosh", "Communication enabled = $isCommunicationEnabled")
```
</TabItem>
</Tabs>

#### Enable SDK communication after consent

Once the user has granted consent, enable communication as follows:

<Tabs>
<TabItem label="Java">

```java
import com.pushwoosh.Pushwoosh;

Pushwoosh.getInstance().startServerCommunication();
```
</TabItem>
<TabItem label="Kotlin">

```kotlin
import com.pushwoosh.Pushwoosh

Pushwoosh.getInstance().startServerCommunication()
```
</TabItem>
</Tabs>

#### Register for push notifications

After communication is enabled, explicitly register for push notifications:

<Tabs>
<TabItem label="Java">

```java
import com.pushwoosh.Pushwoosh;

Pushwoosh.getInstance().registerForPushNotifications();
```
</TabItem>
<TabItem label="Kotlin">

```kotlin
import com.pushwoosh.Pushwoosh

Pushwoosh.getInstance().registerForPushNotifications()
```
</TabItem>
</Tabs>

#### Disable communication

To stop communication with Pushwoosh servers (e.g., if the user revokes consent):

<Tabs>
<TabItem label="Java">

```java
import com.pushwoosh.Pushwoosh;

Pushwoosh.getInstance().stopServerCommunication();
```
</TabItem>
<TabItem label="Kotlin">

```kotlin
import com.pushwoosh.Pushwoosh

Pushwoosh.getInstance().stopServerCommunication()
```
</TabItem>
</Tabs>

### Unity

#### Disable SDK server communication at startup

By default, the communication with the SDK is enabled. To disable all communication with Pushwoosh servers until consent is explicitly granted by the user, apply platform-specific settings:

**Android**

Add the following to your Unity project at `AndroidManifest.xml`:

```xml
 <meta-data android:name="com.pushwoosh.allow_server_communication" android:value="false" />
```

**iOS**

Modify `Info.plist`:

```xml
<key>Pushwoosh_ALLOW_SERVER_COMMUNICATION</key>
<false/>
```


**Note:** You must enable communication before calling `RegisterForPushNotifications`.

#### Check communication status

Use the following method to check whether server communication is currently allowed:

```c#
bool enabled = Pushwoosh.Instance.IsCommunicationEnabled();
```

#### Enable SDK communication after consent

To enable communication after consent:

```c#
Pushwoosh.Instance.SetCommunicationEnabled(true);
```

#### Register for push notifications

Once communication is enabled, you can register the device for push notifications:

```c#
Pushwoosh.Instance.RegisterForPushNotifications();
```

#### Disable communication
To stop communication with Pushwoosh servers (e.g., if the user revokes consent):

```c#
Pushwoosh.Instance.SetCommunicationEnabled(false);
```

### Web Push

#### Disable automatic subscription at startup

By default, the Pushwoosh SDK shows the native subscription prompt as soon as it is initialized. To prevent the SDK from automatically showing the subscription prompt upon initialization, set the `communicationEnabled` parameter to `false` in the `init` call.

```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>
```

#### Enable subscription after consent

Once you have disabled automatic subscription, you can prompt the user to subscribe at any time. When the user agrees to receive push notifications (e.g., by clicking a "Subscribe" button on your custom UI), you can enable communication by calling the `setCommunicationEnabled` method. Calling `Pushwoosh.setCommunicationEnabled(true)` enables communication with Pushwoosh services. Once enabled, the SDK will proceed to show the native browser permission prompt.

```javascript
Pushwoosh.setCommunicationEnabled(true)
  .then(() => {
    console.log('User is subscribed to push notifications.');
  })
  .catch((error) => {
    console.error('Error subscribing user:', error);
  });
```

#### Disable communication

To stop communication with Pushwoosh services (e.g., if the user revokes consent), call `setCommunicationEnabled` with `false`.

```javascript
Pushwoosh.setCommunicationEnabled(false);
```