---
description: Handle consent using AATKit managed consent
---

# Managed Consent

### Introduction

AATKit’s Managed Consent is an easy way to facilitate [IAB TCF](https://iabeurope.eu/transparency-consent-framework/) compliant third-party [Consent Management Platforms](https://iabeurope.eu/tcf-for-cmps/) (CMPs) by providing a unified API and wrappers. In order to make use of Managed Consent, pass an instance of [`AATManagedConsent`](https://ios-sdk.aatkit.com/references/documentation/aatkit/aatmanagedconsent) to your [`AATConfiguration`](https://ios-sdk.aatkit.com/references/documentation/aatkit/aatconfiguration) instance while initializing AATKit.

An [AATManagedConsent](https://ios-sdk.aatkit.com/references/documentation/aatkit/aatmanagedconsent) instance must be initialized with:

* `cmp`: An instance of `AATCMPProtocol`. Currently, supported implementations are `AATCMPGoogle` ([Google CMP](managed-consent/google-cmp)), `AATCMPSourcepoint` ([Sourcepoint CMP](managed-consent/sourcepoint-cmp)), and `AATCMPAppConsent` ([SFBX (AppConsent CMP)](managed-consent/sfbx-appconsent-cmp))   &#x20;
* `delegate`: An instance of an object that conforms to [AATManagedConsentDelegate](broken-reference).

Also, the app needs to trigger the presentation of the CMP by calling `showIfNeeded`. The CMP will only appear if user consent wasn’t asked for recently or is outdated.

{% tabs %}
{% tab title="Swift" %}
```swift
let configuration = AATConfiguration()
configuration.delegate = self
let cmp = <INSTANCE OF AATCMPGoogle OR AATCMPSourcepoint OR AATCMPAppConsent>
var consent = AATManagedConsent(cmp: cmp, delegate: self, showIfNeededSetting: .always)
configuration.consent = consent
AATSDK.initAATKit(with: configuration)
consent?.showIfNeeded(<ROOT VIEW CONTROLLER>)
```
{% endtab %}

{% tab title="Objective-C" %}
```objectivec
AATConfiguration *configuration = [[AATConfiguration alloc] init];
configuration.delegate = self;
AATCMPGoogle *cmp = <INSTANCE OF AATCMPGoogle OR AATCMPSourcepoint OR AATCMPAppConsent>;
AATManagedConsent *consent = [[AATManagedConsent alloc] initWithCmp:cmp delegate:self];
configuration.consent = consent;
[AATSDK initAATKitWith:configuration];
[consent showIfNeeded:<ROOT VIEW CONTROLLER>];
```
{% endtab %}
{% endtabs %}

Added to this, your app must provide a way for the user to edit once given consent settings, e.g. by providing a button in the app’s “Privacy Settings”. This button must trigger `editConsent`.

Also, your instance of the respective CMP used must be set up at its respective backend/dashboard. Please refer to your CMP’s documentation or contact our support.

### Managed Consent States

When the user finishes his consent choice, you can check the consent status via the [AATManagedConsentDelegate](https://ios-sdk.aatkit.com/references/documentation/aatkit/aatmanagedconsentdelegate)'s method: `func managedConsentCMPFinished(with state: AATManagedConsentState)` where [AATManagedConsentState](https://ios-sdk.aatkit.com/references/documentation/aatkit/aatmanagedconsentstate) is an enum with the available (non-IAB) consent states. This shall facilitate a more easy understanding of the complex IAB consent string and is only used for internal purposes (e.g. reporting).

### Re-asking for consent if rejected

If you would like to periodically re-ask users who rejected consent, you can use the public API `showIfNeededOrRejected(daysAgo: Int, viewController: UIViewController)` instead of `showIfNeeded`. In addition to normal `showIfNeeded` behaviour, it will check the consent state and timestamp of the last consent string update. If the consent is rejected and the last update happened more than `daysAgo`, the consent dialog will be shown again.

### Consent Opt-in Status

To set Consent opt-in status, you need to pass `showIfNeededSetting` to `AATManagedConsent` while initializing.

* `showIfNeededSetting` can be one of the following:
  * `always`:  always show the CMP.
  * `never`: never show the CMP, However, the publisher can still call the  `editConsent` API.
  * `serverSideControl`: showing the CMP will be based on the dashboard configurations.
* It has a default value of: `serverSideControl.`

To check the server-side consent opt-in status call `AATSDK.isConsentOptIn()`, which only returns meaningful information after AATKit was successfully initialized (and did download its mediation rules from the backend (If you want to observe this, see [AATDelegate](https://ios-sdk.aatkit.com/references/documentation/aatkit/aatdelegate))).

### Code Examples

* [Example using Google CMP](google-cmp#usage).
* [Example using Sourcepoint CMP](managed-consent/sourcepoint-cmp).
* [Example using SFBX (AppConsent) CMP.](managed-consent/sfbx-appconsent-cmp)
