# Use the new beta privacy APIs

> Implement the new beta privacy APIs by following the opt-in consent, opt-out signal, and age-restricted user specification APIs, respectively, for iOS (Swift, Objective-C) and Android (Kotlin, Java) development.

## Use the new beta privacy APIs

Review the opt-in consent, opt-out signal, and age-restricted specification APIs and relevant code samples for iOS or Android.

### Opt-in consent API

Use the `setUserConsent()` API to display the user's opt-in choices for personalized ads.

Refer to the following tabs for platform-specific code examples to communicate whether the user has granted or declined consent for targeted advertising.

1. **iOS (Swift)**

   ```swift
   public static func setUserConsent(_ consentGranted: Bool)

   // If the user agrees to personalized ads
   UnityAds.setUserConsent(true)

   // If the user doesn't agree to personalized ads
   UnityAds.setUserConsent(false)
   ```

2. **iOS (Objective-C)**

   ```objective-c
   + (void)setUserConsent:(BOOL)consentGranted;

   // If the user agrees to personalized ads
   [UnityAds setUserConsent:YES];

   // If the user doesn't agree to personalized ads
   [UnityAds setUserConsent:NO];
   ```

3. **Android (Kotlin)**

   ```kotlin
   @JvmStatic
   var userConsent: Boolean? = null

   // If the user agrees to personalized ads
   UnityAds.userConsent = true

   // If the user doesn't agree to personalized ads
   UnityAds.userConsent = false
   ```

4. **Android (Java)**

   ```java
   @JvmStatic
   var userConsent: Boolean? = null

   // If the user agrees to personalized ads
   UnityAds.setUserConsent(true);

   // If the user doesn't agree to personalized ads
   UnityAds.setUserConsent(false);
   ```

### Opt-out signal API

Use the `setUserOptOut()` API to display the user's opt-in choices for personalized ads.

Refer to the following tabs for platform-specific code examples to communicate whether the user has granted or declined consent for targeted advertising.

1. **iOS (Swift)**

   ```swift
   public static func setUserOptOut(_ optOut: Bool)

   // If the user opts in to personalized ads
   UnityAds.setUserOptOut(false)

   // If the user opts out to personalized ads
   UnityAds.setUserOptOut(true)
   ```

2. **iOS (Objective-C)**

   ```objective-c
   + (void)setUserOptOut:(BOOL)optOut;

   // If the user opts in to personalized ads
   [UnityAds setUserOptOut:NO];

   // If the user opts out to personalized ads
   [UnityAds setUserOptOut:YES];
   ```

3. **Android (Kotlin)**

   ```kotlin
   @JvmStatic
   var userOptOut: Boolean? = null

   // If the user opts in to personalized ads
   UnityAds.userOptOut = false

   // If the user opts out to personalized ads
   UnityAds.userOptOut = true
   ```

4. **Android (Java)**

   ```java
   @JvmStatic
   var userOptOut: Boolean? = null

   // If the user opts in to personalized ads
   UnityAds.setUserOptOut(false);

   // If the user opts out to personalized ads
   UnityAds.setUserOptOut(true);
   ```

### Age-restricted users specification

Use the `setNonBehavioral()` API to indicate a user's eligibility for non-behavioral (contextual) ads.

Refer to the following tabs for platform-specific code examples to communicate whether a privacy framework requires contextual-only ad delivery, typically for content directed to children or younger users.

1. **iOS (Swift)**

   ```swift
   public static func setNonBehavioral(_ nonBehavioral: Bool)

   // If the user opts out to personalized ads
   UnityAds.setNonBehavioral(true)

   // If the user opts in to personalized ads
   UnityAds.setNonBehavioral(false)
   ```

2. **iOS (Objective-C)**

   ```objective-c
   + (void)setNonBehavioral:(BOOL)nonBehavioral;

   // If the user opts out to personalized ads
   [UnityAds setNonBehavioral:YES];

   // If the user opts in to personalized ads
   [UnityAds setNonBehavioral:NO];
   ```

3. **Android (Kotlin)**

   ```kotlin
    @JvmStatic
   var nonBehavioral: Boolean? = null

   // If the user opts out to personalized ads
   UnityAds.nonBehavioral = true

   // If the user opts in to personalized ads
   UnityAds.nonBehavioral = false
   ```

4. **Android (Java)**

   ```java
   @JvmStatic
   var nonBehavioral: Boolean? = null

   // If the user opts out to personalized ads
   UnityAds.setNonBehavioral(true);

   // If the user opts in to personalized ads
   UnityAds.setNonBehavioral(false);
   ```
