How to integrate UniConsent CMP SDK for iOS with mobile apps

UniConsent CMP is a package for handling GDPR IAB TCF 2.2 consent management in IOS. You can find a demo app integrated with UniConsent CMP in the "uniconsent_demo" directory.

Prerequisites

  • UniConsent CMP plan with Mobile app support
  • iOS >= 14.0
  • UniConsent CMP SDK package (request from support)

Getting started

Add UniConsent.framework into your project, make sure it is Embed & Sign.

Usage

To use the UniConsent CMP in your app, follow these steps:

Initialize the CMP with an App ID from your account manager:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    // Init CMP with appId
    UniConsent.shared.initialize(apiId: "YOUR_APP_ID_CHANGE_THIS")
    return true
}

Display the CMP UI:

// Display CMP UI
UniConsent.shared.setUIStage(.GDPRFirstScreen)
UniConsent.shared.launchCMP(rootVC: self)

Automatically check if consent is expired when the vendorList updates:

// Automatic check if consent is expired when vendorList updates
UniConsent.shared.shouldRequestConsent()

Get the tcString if required:

// Get tcString if requried
UniConsent.shared.getTCString()

Read the consent status:

// Read consent status
UniConsent.shared.isAllowPurposeById(purposeId: 1)

Reset consent status if required:

// Reset consent status if required:
UniConsent.shared.clearConsentData();

Setup default consent status KV:

<key>FIREBASE_ANALYTICS_COLLECTION_ENABLED</key> <false/>

<key>GOOGLE_ANALYTICS_DEFAULT_ALLOW_ANALYTICS_STORAGE</key> <false/>
<key>GOOGLE_ANALYTICS_DEFAULT_ALLOW_AD_STORAGE</key> <false/>
<key>GOOGLE_ANALYTICS_DEFAULT_ALLOW_AD_USER_DATA</key> <false/>
<key>GOOGLE_ANALYTICS_DEFAULT_ALLOW_AD_PERSONALIZATION_SIGNALS</key> <false/>

Control analytics based on the consent flags:

public func onDismiss() {

    if(UniConsent.shared.isAllowPurposeById(purposeId: 1)) {
        Analytics.setConsent([
          .analyticsStorage: .granted,
          .adStorage: .granted,
          .adUserData: .granted,
          .adPersonalization: .granted,
        ]) 
        Analytics.setAnalyticsCollectionEnabled(true);
    } else {
        Analytics.setConsent([
          .analyticsStorage: .denied,
          .adStorage: .denied,
          .adUserData: .denied,
          .adPersonalization: .denied,
        ]) 
        Analytics.setAnalyticsCollectionEnabled(false);
    }
}

Find more info at Set up consent mode for apps

Notes

  1. Users should have the ability to access a "Privacy Settings" button or link in the settings section of your application in order to open the CMP UI.
  2. You can utilize the shouldRequestConsent() function to check whether you should request new consent based on the status. Display the CMP UI as needed when a user opens the application.