iubenda SDK v3.5 – IOS – API documentation

The CMPManager class provides methods to manage user consent for data processing and tracking. This documentation covers the main methods available for mobile app integration.

Initialization

UrlConfig()

Sets the URL configuration for the iubenda SDK. Needs to be initialized with the value below, and passed to the getInstance method. 

Parameters:

  • id: String – Your site-specific configuration retrieved on the embedding section of your Privacy Controls and Cookie Solution embedding section
  • domain: String – The domain for iubenda CDN
  • language: String – The language code (e.g., “EN”, “IT”, “DE”, etc)
  • appName: String – The name of your app, used only for reporting purposes
  • jsonConfig: JSON Object – Optional, can be useful to inject a local configuration direcl inside the mobile SDK 

Example:

CMPManager.shared.setUrlConfig(UrlConfig(
    id: "0a000000000a1",	// The Code-ID retrieved from your CMP dashboard
    domain: "cdn.iubenda.com",  // The domain retrieved from your CMP dashboard
    language: "EN",		// Language code, examples: IT, DE, EN, etc. 
    appName: "MyApp"		// The name of your app, used for reporting purposes on your CMP dashboard
))

setWebViewConfig()

Configures the appearance and behavior of the consent WebView. You can set the position where the WKWebiew object displaying the consent layer will appear, like full screen, on the lower half of the screen or its upper half. Also, the background style can be applied, as well as the corner radius, whether it will respect the safe area of the device, as well as whether it will respond to orientation changes or not, in case your mobile works only in one single orientation, which usually happens with games that only use the horizontal configuration of the device’s screen.   

Parameters:

  • config: A ConsentLayerUIConfig object with the following properties:
  • position: Position – The position of the WebView (e.g., .fullScreen)
  • backgroundStyle: BackgroundStyle – The background style (e.g., .dimmed)
  • cornerRadius: CGFloat – The corner radius of the WebView
  • respectsSafeArea: Bool – Whether to respect the safe area
  • allowsOrientationChanges: Bool – Whether to allow orientation changes

Returns: Void

Example:

CMPManager.shared.setWebViewConfig(ConsentLayerUIConfig(
    position: .fullScreen,
    backgroundStyle: .dimmed(.black, 0.5),
    cornerRadius: 10,
    respectsSafeArea: true,
    allowsOrientationChanges: true
))

setPresentingViewController()

Sets the view controller that will present the consent layer. Usually you pass self as the current View Controller. 

Parameters:

  • viewController: UIViewController – The view controller to present the consent layer

Returns: Void

Example:

CMPManager.shared.setPresentingViewController(self)

getUserStatus()

Returns a detailed snapshot of the user’s current consent status and preferences. This method provides comprehensive information about the user’s consent choices, including their overall consent status, individual vendor permissions, purpose-specific consents, and relevant consent strings.

Parameters:

  • None

Returns:

Return Type: CMPUserStatusResponse object, explained in the code below. 

Example:

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)

checkAndOpen()

Checks with the server if consent is required and opens the consent layer if necessary. This will make a network call to our servers via the WKWebView created inside our SDK, consuming one pageview in the process. This network call will send a message to our backend via JavaScript, which will detect whether the device has a valid consent or not, which will in turn determine whether the consent layer needs to be displayed or not.  

Parameters:

  • jumpToSettings: A boolean value to determine whether the consent layer displayed will automatically lead to the page where a more granular control over the consents given by the users, allowing them to fine tune their choices (when set to true) or the initial default screen with the buttons (when set to false or suppressed).
  • completion: A closure called when the operation completes.

Returns: Void

Example:

CMPManager.shared.checkAndOpen { error in
    if let error = error {
        print("Error: \(error.localizedDescription)")
    } else {
        print("Check completed successfully")
    }
}

forceOpen()

Parameters:

  • jumpToSettings: A boolean value to determine whether the consent layer displayed will automatically lead to the page where a more granular control over the consents given by the users, allowing them to fine tune their choices (when set to true) or the initial default screen with the buttons (when set to false or suppressed).
  • completion: A closure called when the operation completes, returning either a sucess or an error.

Returns: Void

Example:

CMPManager.shared.forceOpen { error in
    if let error = error {
        print("Error: \(error.localizedDescription)")
    } else {
        print("Consent layer opened successfully")
    }
}

exportCMPInfo()

Exports the current consent information stored on the device as a string. This method retrieves the consent string from the UserDefaults area of the device and returns it. Usually this information is passed to the importCMPInfo method.

Returns: String – The exported consent information

Example:

let cmpInfo = CMPManager.shared.exportCMPInfo()
print("Exported CMP info: \(cmpInfo)")

getGoogleConsentModeStatus()

Seamlessly integrates with Consent Mode, a Google technology that enables conversion and analytics modeling, allowing Google’s services to fill in data gaps when users do not consent. This function translates the user’s consent from your CMP into a format that Firebase Analytics can understand, so you can simply get the return of this method and pass it along to Firebase .setConsent method.

  • It then updates Google Analytics with the user’s current consent status.

Parameters:

  • None

Returns: [String: String] – An key value array with the four Google Consent Mode keys: .analyticsStorage.adStorage.adUserData and .adPersonalization, and their respective values in terms of .choiceDoesntExist.granted or .denied.

Example:

showToast(message: "Google Consent Mode Status: \n \(CMPManager.shared.getGoogleConsentModeStatus())")

getStatusForPurpose()

Parameters:

  • id: String – The ID of the purpose to check

Returns: UniqueConsentStatus – An enum with the values .choiceDoesntExist if no consent was given, .granted or .denied.

Example:

let purposeStatus = CMPManager.shared.getStatusForPurpose(id: "c53")
var message = "Purpose c53 status: "
switch purposeStatus {
   	case .choiceDoesntExist: message += "No Choice"
    case .granted: message += "Granted"
    case .denied: message += "Denied"
    @unknown default: message += "No Choice"
}

acceptAll()

Parameters:

  • completion: A closure called when the operation completes

Returns: Void

Example:

CMPManager.shared.acceptAll { error in
    if let error = error {
        print("Error: \(error.localizedDescription)")
    } else {
        print("All consents accepted successfully")
    }
}

acceptPurposes()

Parameters:

  • purposes: [String] – An array of purpose IDs to accept
  • updatePurpose: Bool – Whether to update related purposes
  • completion: A closure called when the operation completes

Returns: Void

Example:

CMPManager.shared.acceptPurposes(["2", "3"], updatePurpose: true) { error in
    if let error = error {
        print("Error: \(error.localizedDescription)")
    } else {
        print("Purposes accepted successfully")
    }
}

importCMPInfo()

Parameters:

  • cmpString: String – The CMP string to import
  • completion: A closure called when the operation completes

Returns: Void

Example:

let cmpString = "Q1FERkg3QVFERkg3QUFmR01CSVRCQkVnQUFBQUFBQUFBQWlnQUFBQUFBQUEjXzUxXzUyXzUzXzU0XzU1XzU2XyNfczI3ODlfczI3OTBfczI3OTFfczI2OTdfczk3MV9VXyMxLS0tIw"
CMPManager.shared.importCMPInfo(cmpString) { error in
    if let error = error {
        print("Error: \(error.localizedDescription)")
    } else {
        print("CMP info imported successfully")
    }
}

rejectAll()

Parameters:

  • completion: A closure called when the operation completes

Returns: Void

Example:

CMPManager.shared.rejectAll { error in
    if let error = error {
        print("Error: \(error.localizedDescription)")
    } else {
        print("All consents rejected successfully")
    }
}

rejectPurposes()

Parameters:

  • purposes: [String] – An array of purpose IDs to reject
  • updateVendor: Bool – Whether to update related vendors
  • completion: A closure called when the operation completes

Returns: Void

Example:

CMPManager.shared.rejectPurposes(["2", "3"], updateVendor: true) { error in
    if let error = error {
        print("Error: \(error.localizedDescription)")
    } else {
        print("Purposes rejected successfully")
    }
}

resetConsentManagementData()

Parameters:

  • completion: A closure called when the operation completes

Returns: Void

Example:

CMPManager.shared.resetConsentManagementData { error in
    if let error = error {
        print("Error: \(error.localizedDescription)")
    } else {
        print("Consent management data reset successfully")
    }
}

Passing consent data to third-party SDKs

updateThirdPartyConsent

This method handles the automatic passing of consent data to third-party SDKs like AppsFlyer, AdJust, Branch, Kochava, Singular, AirBridge and Tenjin. It works via introspection/reflection, so initialize the third-party SDK with your credentials using the usual strategy recommended by the provider, and our CMP SDK will detect the instance of the 3P SDK and invoke the needed methods under the hood. 

CMPManagerDelegate events

The SDK provides a flexible link handling mechanism that allows applications to customize how URLs within the consent layer are handled. By default, all links open within the WebView, but applications can intercept specific URLs to handle them externally when needed.

// Example 1: Handle specific domains in external browser
cmpManager.setLinkClickHandler { url in
    // Handle links to specific domains externally
    if url.host?.contains("google.com") == true || 
       url.host?.contains("facebook.com") == true {
        UIApplication.shared.open(url, options: [:], completionHandler: nil)
        return true // URL handled externally
    }
    
    // Let other URLs load in the WebView
    return false
}

// Example 2: Handle URLs based on scheme
cmpManager.setLinkClickHandler { url in
    // Open mail links in mail app
    if url.scheme == "mailto" {
        UIApplication.shared.open(url, options: [:], completionHandler: nil)
        return true
    }
    
    // Open tel links in phone app
    if url.scheme == "tel" {
        UIApplication.shared.open(url, options: [:], completionHandler: nil)
        return true
    }
    
    // Let all other URLs load in the WebView
    return false
}

didReceiveConsent(consent: String, jsonObject: [String: Any])

This is triggered when the consent layer was closed after the user updating his/her consents OR when invoking methods that cause changes in the consents, like acceptAll, rejectAll, acceptVendors, rejectVendors, etc. It means that the user accepted of rejected some of all of the consents, and that those were correctly saved in the device.

didShowConsentLayer

This is triggered when the consent layer was actually displayed. It means that there was not a consent valid in the device, so a new one should be collected.

didCloseConsentLayer

This is triggered when the SDK checked the need for a consent, but it was not needed and the layer was not displayed. It means that there is already a valid in the device, so a new one is not necessary and tue consent layer will not be displayed.

didReceiveError

This is triggered when the SDK faced any error, returning its code.