Installation
consentmanager SDK is a comprehensive solution for managing user consent in mobile applications. Designed to handle GDPR compliance, user privacy preferences, and ad tracking transparency, this SDK provides a seamless integration for iOS and Android platforms.
Steps – High Level Description
- Integration and Configuration:
- Integrate the SDK into your app.
- Configure the SDK settings according to your needs.
- Creating an Instance and displaying the Consent Layer:
- On app startup, create an instance of the
CMPManager
class. This instance will handle the consent process. - The SDK will automatically display the consent screen if needed.
- On app startup, create an instance of the
- Processing user’s consent data:
- Once consents are collected, info is stored and is available for querying through different properties and methods exposed by our SDK. You’ll have information about rejected or accepted consents, vendors and purposes.
1.1 Integration and Configuration
Option 1: CocoaPods
Add the following line to your Podfile:
pod 'cm-sdk-ios-v3', '3.5.0'
Then run:
pod install --repo-update
Option 2: Swift Package Manager
- Download the latest XCFramework from our GitHub releases page.
- On XCode, go to the menu
File
>Add Package Dependency
. - Add the SDK Repository URL above
- SPM will now fetch the repository and ask you to select a version.
You can choose to add the package by selecting a version rule:
–Up to Next Major
: This will update the package up to the next major version. It is the recommended option as it adds updates which do not have breaking changes.
–Up to Next Minor
: This will update the package up to the next minor version.
–Exact
: This will lock the package to a specific version. No updates will be installed. - Import the SDK by inserting in the top of the classes implementing the SDK’s methods the line below:
import cm_sdk_ios_v3
In your target’s settings, go to “General” > “Frameworks, Libraries, and Embedded Content” and ensure the framework is set to “Embed & Sign”.
1.2 Creating an instance and displaying consent layer
In your app’s viewDidLoad, follow these steps to set up the CMP SDK:
- Create a CMPManager instance using the getInstance method.
- Define two configuration objects:
UrlConfig
: Contains settings like your iubenda embedding code and the language of the banner.ConsentLayerUIConfig
: Defines the appearance of the consent screen shown in a WKWebView.
- Set the current ViewController by calling
setPresentingViewController
. - Call
checkAndOpen()
- This checks with the server to decide if the consent screen should appear.
- If needed, the SDK automatically shows the consent layer inside a
WKWebView
, using your configurations. - The SDK then collects and saves consent info to
NSUserDefaults
, enabling targeted ads as appropriate.Assign the delegate to handle CMP events
import cm_sdk_ios_v3
class YourViewController: UIViewController, CMPManagerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
let cmpManager = CMPManager.shared
cmpManager.setUrlConfig(UrlConfig(
id: "your_id_here", // example: a000aaaaa1a
domain: "cdn.iubenda.com", // usually, delivery.consentmanager.net
language: "your_language_here", // example: DE
appName: "Your App Name")) // example: testApp
cmpManager.setWebViewConfig(ConsentLayerUIConfig(
position: .fullScreen,
backgroundStyle: .dimmed(.black, 0.5),
cornerRadius: 5,
respectsSafeArea: true,
allowsOrientationChanges: true))
cmpManager.setPresentingViewController(self)
cmpManager.delegate = self
cmpManager.checkAndOpen { error in
if let error = error {
print("Error initializing consent: \(error)")
} else {
print("ConsentManager initialized and consent received and stored on the device's NSUserDefaults.")
}
}
}
1.3 Processing users’ consent data
Checking users’s consents
Our SDK offer a unified method to check and retrieve consent information, getUserStatus()
:
let status = CMPManager.shared.getUserStatus()
var message = "Status: \(status.status)\n\n"
message += "Vendors:\n"
for (vendorId, state) in status.vendors {
message += "- \(vendorId): \(state)\n"
}
message += "\nPurposes:\n"
for (purposeId, state) in status.purposes {
message += "- \(purposeId): \(state)\n"
}
message += "\nTCF: \(status.tcf)\n"
message += "Additional Consent: \(status.addtlConsent)\n"
message += "Regulation: \(status.regulation)"
print(message)
For further information about the other methods, please refer to our full API Documentation.
Reopening the Consent Layer to check the users’ choices
In order to allow the user to verify or change their choices, you can simply call openConsentLayer()
cmpManager.forceOpen()
Importing/Exporting consent information to other sources
In some cases an native app might contain webviews in order to display information, like advertising or content. In order to transmit the consent information from the SDK to the webview, you can retrieve the consent string using:
consentData = cmpManager.exportCMPInfo()
This will export the consent information and all further data that is needed by the CMP. You can then pass this information to the CMP that is in your webview by adding it to the URL that is called in the webview.
If, otherwise, you need to import the consent string using the SDK, you can use the example below:
let consentStringToImport = "Q1FERkg3QVFERkg3QUFmR01CSVRCQkVnQUFBQUFBQUFBQWlnQUFBQUFBQUEjXzUxXzUyXzUzXzU0XzU1XzU2XyNfczI3ODlfczI3OTBfczI3OTFfczI2OTdfczk3MV9VXyMxLS0tIw"
cmpManager.importCMPInfo(consentStringToImport)
Integration with Apple Tracking Transparency (ATT)
In case you are using tracking or analytics in your app, we recommend to read the guide on ATT implementation here.
Creating a custom layout
To create a customized view of the WKWebView, like changing its positioning or background, for example, you can change the configuration passed to the ConsentLayerUIConfig object like below:
ConsentLayerUIConfig(
position: .halfScreenTop,
backgroundStyle: .dimmed(.grey, 0.75),
cornerRadius: 20,
respectsSafeArea: false,
allowsOrientationChanges: true)
Logging
When using our iOS SDK, you may find the need to debug or analyze log information for various purposes. The logs generated by our SDK are tagged under “CMP”, allowing you to easily filter and view only the relevant logs.