Info
Content

[iOS] 3. API Documentation

initialize


Initialize function will initialize the consent layer and checks automatically if the user needs a consent or not. This function will eventually open the consent layer and Will interact wit the Apple Tracking Transparency API to ask the user for Consent

Return

CMPConsentTool

Example
let cmpConfig : CmpConfig = CmpConfig.shared.setup(withId: config.appId, domain: config.domain, appName: config.appName, language: config.language);
// Creating the Instance and chaining the initialize function. This can be done also separately 
cmpConsentTool = CMPConsentTool(cmpConfig: cmpConfig).initialize()

 

withCloseListener


Adds a close listener to receive notifications when the consent layer is being closed.

Parameters
Name Type Description
closeListener function Callback which will be called when the consent layer is closed.
Return

CMPConsentTool

Example
func onClose() -> Void {
      NSLog("APP:CLOSED");
      // add custom business logic here
}
cmpConsentTool = CMPConsentTool(cmpConfig: cmpConfig, viewController: self)
            .withCloseListener(onClose)

withOpenListener


Adds an open listener to receive notifications when the consent layer is being opened.

Parameters
Name Type Description
openListener function Callback which will be called when the consent layer is opened
Return

CMPConsentTool

Example
func onOpen() -> Void {
      NSLog("APP:CLOSED");
      // add custom business logic here
}
cmpConsentTool = CMPConsentTool(cmpConfig: cmpConfig, viewController: self)
            .withCloseListener(onOpen)

 

 

withErrorListener


Adds an error listener to receive notifications when an error occurred

Parameters
Name Type Description
errorListener function Callback to add action if an error occurred.
Return

CMPConsentTool

Example
func onCMPError(type: CmpErrorType, message: String?) -> Void {
    switch type {
    case .networkError:
        print(message)
        print("error network")
        break
    case .timeoutError:
        print(message)
        print("error timeout")
        break
    case .consentDataReadWriteError:
        print(message)
        print("error consent read/write")
        break
    case .unknownError:
        print(message)
        print("error unknown")
        break
    @unknown default:
        print(message)
        print("error network")
        break
    }
}
cmpConsentTool = CMPConsentTool(cmpConfig: cmpConfig, viewController: self)
            .withErrorListener(onCMPError)

 

withOnCMPNotOpenedListener


Adds a Cmp not opened callback to get notification when consent layer is not opening

Parameters
Name Type Description
openListener function Callback which will be called when the consent layer is `not opened`. Most common reason is that the user already gave a consent
Return

CMPConsentTool

Example
func onCMPNotOpened() -> Void {
      NSLog("APP:CLOSED");
      // add custom business logic here
}
cmpConsentTool = CMPConsentTool(cmpConfig: cmpConfig, viewController: self)
            .withOnCMPNotOpenedListener(onCMPNotOpened)

 

withOnCmpButtonClickedCallback


Sets a callback to receive notifications when the user clicks a button to close the consent layer.

Parameters
Name Type Description
openListener function Callback that will be invoked with the ``CmpButtonEvent`` indicating which button was pressed
Return

CMPConsentTool

Example
func onButtonClickedEvent(event: CmpButtonEvent) -> Void {
    switch event {
    case .acceptAll:
        print("user accepted all")
        break
    case .rejectAll:
        print("user accepted all")
        break
    case .save:
        print("user saved custom settings")
        break
    case .close:
        print("user closed consent layer without giving consent")
        break
    @unknown default:
        print("unknown button event")
    }
}
cmpConsentTool = CMPConsentTool(cmpConfig: cmpConfig, viewController: self)
            .withOnCmpButtonClickedCallback(onButtonClickedEvent)

 

withCmpViewControllerConfigurationBlock


Customise the consentlayer UIViewController

Parameters
Name Type Description

configurationBlock

CmpViewControllerConfigurationBlock

Customise the consentlayer

UIViewController

Return

CMPConsentTool

Example
cmpConsentTool = CMPConsentTool(cmpConfig: cmpConfig)
            .withCmpViewControllerConfigurationBlock({ viewController in
                viewController?.modalPresentationStyle = .formSheet
            })

 

withCmpViewConfigurationBlock


Customise the UiView of the consentlayer

Parameters
Name Type Description

configurationBlock

CmpUIViewConfigurationBlock

Customise the consentlayer

UiView

Return

CMPConsentTool

Example
let cmpLayout = CmpLayout.default()
        cmpLayout?.cornerRadius = 10.0
        cmpLayout?.customLayout = CGRect(x: 0, y: 0, width: 200, height: 300)
cmpConsentTool = CMPConsentTool(cmpConfig: cmpConfig)
                        .withCmpViewConfigurationBlock({ uiView in
                cmpLayout?.apply(to: uiView)
            })

 

withUpdateGoogleConsent


Retrieve google consentmode status 

Parameters
Name Type Description

consentMap

[String: String]?

Consent status
Return

CMPConsentTool

Example
       cmpConsentTool = CMPConsentTool(cmpConfig: cmpConfig)
            .withUpdateGoogleConsent(onCmpUpdateGoogleConsent)
    }

    func onCmpUpdateGoogleConsent(consentMap: [String: String]?) -> Void {
        guard let consentMap = consentMap else { return }

        var firebaseConsentMap: [ConsentType: ConsentStatus] = [:]

        consentMap.forEach { key, value in
            if let consentType = convertToFirebaseConsentType(from: key),
               let consentStatus = convertToFirebaseConsentStatus(from: value) {
                firebaseConsentMap[consentType] = consentStatus
            }
        }

        Analytics.setConsent(firebaseConsentMap)
    }

    func convertToFirebaseConsentType(from key: String) -> ConsentType? {
        switch key {
        case "analytics_storage":
            return .analyticsStorage
        case "ad_storage":
            return .adStorage
        case "ad_user_data":
            return .adUserData
        case "ad_personalization":
            return .adPersonalization
        default:
            return nil
        }
    }

    func convertToFirebaseConsentStatus(from value: String) -> ConsentStatus? {
        switch value {
        case "granted":
            return .granted
        case "denied":
            return .denied
        default:
            return nil
        }
    }

 

checkAndOpenConsentLayer


Check and open consent layer

Return

No return value

Example
cmpConsentTool.checkAndOpenConsentLayer()

 

openCmpConsentToolView


Opens the CMP consent layer view

Return

No return value

Example
cmpConsentTool.openView()

 

check


Check

Parameters
Name Type Description
onCmpLayerOpen function Callback when the consent layer needs to be open.
isCached Boolean BOOL flag when TRUE, the request will be cached and the response will be saved
Return

No return value

Example
cmpConsentTool?.check(
  	{
		print("Layer wants to open")
    	// self.cmpConsentTool?.openView()
    }, 
    isCached: true, 
    onCmpLayerNotOpen: {
     	print("Layer does not want to open")
    }
)

hasConsent


Checks if the user gave a consent. The consent layer can have the option to just close the layer by. In this case the user does not gave a consent.

Return
Example
cmpConsentTool.hasConsent()

 

getAllPurposes


Gets a comma separated String of the disabled `purpose` IDs

Return

String of all `purpose` IDs

Example
cmpConsentTool.getAllPurposes()

 

getAllPurposeList


Retrieves a list of all `purpose` IDs for the given Cmp.

Return

A `List` containing all `purpose` IDs.

Example
cmpConsentTool.getAllPurposeList()

 

getEnabledPurposes


Gets a comma separated String of the enabled `purpose` IDs

Return

`String` of enabled `purpose` IDs

Example
cmpConsentTool.getEnabledPurposes()

 

getEnabledPurposeList


Get agreed purpose list

Return

 

Example
cmpConsentTool?.getEnabledPurposeList()

 

getDisabledPurposes


Get disabled purposes

Return

 

Example
cmpConsentTool?.getDisabledPurposes()

 

getAllVendors


Get all vendors

Return

 

Example
cmpConsentTool?.getAllVendors()

 

getAllVendorsList


Get all vendors list

Return

 

Example
cmpConsentTool?.getAllVendorsList()

 

getEnabledVendors


Get enabled vendors

Return

 

Example
cmpConsentTool?.getEnabledVendors()

 

getEnabledVendorList


Get enabled vendor list

Return

 

Example
cmpConsentTool?.getEnabledVendorList()

 

getDisabledVendors


Get disabled vendors

Return

 

Example
cmpConsentTool?.getDisabledVendors()

 

enableVendorList


Enables a list of vendors and updates the given consen

Parameters
Name Type Description
vendors Array List of vendor ids to enable.
onFinish function Callback for handling consent received event. it will be called when consent is received and processed.
Return

No return value

Example
func onFinish() -> Void {
    NSLog("Notification, that new consent is received");
}
let vendors = ["1","2"]
cmpConsentTool?.enableVendorList(vendors, onFinish: onFinish)

 

disableVendorList


Disables a list of vendors and updates the given consent

Parameters
Name Type Description
vendors Array List of vendor ids to disable.
onFinish function Callback for handling consent received event. it will be called when consent is received and processed.
Return

No return value

Example
func onFinish() -> Void {
    NSLog("Notification, that new consent is received");
}
let vendors = ["1","2"]
cmpConsentTool?.disableVendorList(vendors, onFinish: onFinish)

 

enablePurposeList


Enables a list of purposes and updates the given consent

Parameters
Name Type Description
purposes Array List of purpose ids to enable.
onFinish function (Optional) Callback for handling consent received event. it will be called when consent is received and processed.
Return

No return value

Example
func onFinish() -> Void {
    NSLog("Notification, that new consent is received");
}
let vendors = ["1","2"]
cmpConsentTool?.enablePurposeList(vendors, onFinish: onFinish)

// or without callback
cmpConsentTool?.enablePurposeList(vendors)

 

disablePurposeList


Disables a list of purposes and updates the given consent

Parameters
Name Type Description
purposes Array List of purpose ids to disable.
onFinish function (Optional) Callback for handling consent received event. it will be called when consent is received and processed.
Return

No return value

Example
func onFinish() -> Void {
    NSLog("Notification, that new consent is received");
}
let vendors = ["1","2"]
cmpConsentTool?.disablePurposeList(vendors, onFinish: onFinish)

// or without callback
cmpConsentTool?.disablePurposeList(vendors)

 

rejectAll


Rejects the consent layer and behaves the same when the user `did not accept` the consent

Parameters
Name Type Description
onFinish function Callback for handling consent received event. it will be called when consent is received and processed.
Return

No return value

Example
func onFinish() -> Void {
    NSLog("Notification, that new consent is received");
}
cmpConsentTool.rejectAll(onFinish)

 

acceptAll


Accepts the consent layer and behaves the same when the user `did accepts` the consent

Parameters
Name Type Description
onFinish function Callback for handling consent received event. it will be called when consent is received and processed.
Return

No return value

Example
func onFinish() -> Void {
    NSLog("Notification, that new consent is received");
}
cmpConsentTool.acceptAll(onFinish)

 

getUSPrivacyString


Get US Privacy String

Return

`String` The US Privacy String, that was set by consentmanager

Example
cmpConsentTool.getUSPrivacyString()

 

hasVendorConsent


Has vendor consent

Parameters
Name Type Description
vendorId String vendor id
vendorIsV1orV2 BOOl if vendor id is an IAB vendor. (deprecated: The flag is not needed anymore)
Return
Example
cmpConsentTool.hasVendorConsent("vendorID")

 

hasPurposeConsent


Checks if the purpose ID is enabled based on the user consent.

Parameters
Name Type Description
purposeId String purpose id
vendorIsV1orV2 BOOl if vendor id is an IAB vendor. (deprecated: The flag is not needed anymore)
Return

 

Example
cmpConsentTool.hasPurposeConsent("purposeID")

 

getGoogleACString


Retrieves the Google add ID (`addtlConsent`) string that was set by the consent manager.

Return

Google AC String

Example
cmpConsentTool.getGoogleACString()

 

getConsentstring


Get last consent string

Return
Example
getConsentstring()

 

exportCmpString


Exports the CmpData String

Return

The CmpData String base64 encoded

Example
CMPConsentTool.exportCmpString()

 

consentRequestedToday


Checks if the consent layer was requested today

Return

TRUE if the CMPConsent Manager Server was requested today, otherwise FALSE

Example
cmpConsentTool.consentRequestedToday()

 

isConsentRequired


Checks if the user needs acceptance

Return

TRUE if the user needs to give a consent.

Example
cmpConsentTool.isConsentRequired()

 

reset


Resets all data set by the ``CMPConsentTool``

Return

No return value

Example
CMPConsentTool.reset()

 

Back to top