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.
CMPManager class. This instance will handle the consent process.Add the following line to your Podfile:
pod 'cm-sdk-ios-v3', '3.5.0'
Then run:
pod install --repo-update
File > Add Package Dependency.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 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”.
In your app’s viewDidLoad, follow these steps to set up the CMP SDK:
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.setPresentingViewController.checkAndOpen()
WKWebView, using your configurations.NSUserDefaults, enabling targeted ads as appropriate.Assign the delegate to handle CMP eventsimport 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.")
}
}
}
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.
In order to allow the user to verify or change their choices, you can simply call openConsentLayer()
cmpManager.forceOpen()
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)
In case you are using tracking or analytics in your app, we recommend to read the guide on ATT implementation here.
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)
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.