Info
Content

[iOS] 3. API Documentation

API


 

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

          cmpConsentTool = CMPConsentTool(cmpConfig: cmpConfig, viewController: self)
            .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)

 

 

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({() -> Void in
  print("Notification, that consent layer needs to be open")
}, isCached: false)

 

openCustomLayer


opens the customized consent layer

Parameters
Name Type Description
context Context Application Context
appInterface CmpLayerAppEventListenerInterface  
Return

No return value

Example
openCustomLayer(context = ...,appInterface = ...)

 

openConsentLayer


opens the consent layer

Return

No return value

Example
openConsentLayer()

 

createCustomLayerFragment


Create custom layer fragment

Return

CmpLayerFragment

Example
createCustomLayerFragment()

 

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
getEnabledPurposes()

 

getEnabledPurposeList


Get agreed purpose list

Return

 

Example
getEnabledPurposeList()

 

getDisabledPurposes


Get disabled purposes

Return

 

Example
getDisabledPurposes()

 

getAllVendors


Get all vendors

Return

 

Example
getAllVendors()

 

getAllVendorsList


Get all vendors list

Return

 

Example
getAllVendorsList()

 

getEnabledVendors


Get agreed vendors

Return

 

Example
getEnabledVendors()

 

getEnabledVendorList


Get agreed vendor list

Return

 

Example
getEnabledVendorList()

 

getDisabledVendors


Get disabled vendors

Return

 

Example
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", FALSE)

 

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", FALSE)

 

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()

 

calledThisDay


Checks if the consent layer was called today

Return

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

Example
cmpConsentTool.calledThisDay()

 

needsAcceptance


Checks if the user needs acceptance

Return

TRUE if the user needs to give a consent.

Example
cmpConsentTool.needsAcceptance()

 

reset


Resets all data set by the ``CMPConsentTool``

Return

No return value

Example
CMPConsentTool.reset()

 

Back to top