OneTrust SDK Helpers

OneTrust iOS SDK Public Methods for Initial SDK Setup

Existing

Starting OneTrust SDK Setup

Starts the OneTrust SDK, downloads and parses the data and returns the response required to setup OneTrust SDK.

OTPublishersHeadlessSDK.shared.startSDK(storageLocation:, domainIdentifier:, languageCode:, params:, loadOffline:, completionHandler:)

Parameters

  • storageLocation: Contains the storage location from where data has to be fetched (ex: "cdn.cookielaw.org").
  • domainIdentifier: Contains unique Domain Identifier to be passed (ex: "5376c4e0-8367-450c-8669-a0d41bed69ac").
  • languageCode: Contains valid ISO Language code for language for which localized data has be fetched (ex: "en").
  • params: Optional parameter containing additional SDK parameters like country, region code, profile parameters etc.
  • loadOffline: Sets up the OT SDK using offline data that is set via API setOTOffileData(_:). By default this value will be set to false.
  • completionHandler: The block of code that will be triggered once the startSDK setup is complete. Completion Handler contains response object that contains either the server response in the form of a string or an error object if in case the call has failed.

Note: This call would fail if there are internet connectivity issues, invalid storage url/domain-Identifier/language-code is passed.

Note: If the application wants to determine if OneTrust UI should be shown or not and based on that if OneTrust itself has to show the UI, please call setupUI(_:, UIType:) prior to calling this method.

Determine if OneTrust SDK should be shown

Determines whether the OneTrust SDK UI should be shown based on the user's location and whether the user has already provided consent. If consent has been given previously, the UI will not be displayed.

OTPublishersHeadlessSDK.shared.shouldShowBanner()

Returns

  • true - banner should be shown
  • false - banner will not be shown based on user's geolocation / consent has already been given.
OTPublishersHeadlessSDK.shared.showPreferenceCenterUI()

Enabling Logging for OneTrust SDK

Use this API to set the logging level of the OT SDK.

Parameter:

  • level: Log level which has to be printed on console.
    • Values: .noLogs, .error, .warning, .info, .debug, .verbose.

Note: For any valid logLevel passed SDK will log that level and above level. For instance: If level .info is passed, then error, warning and info logs will be printed.

OTPublishersHeadlessSDK.shared.enableOTSDKLog(_:)

Writing OneTrust logs to File

Use this API to write logs to the log file created and maintained by OT SDK.

OTPublishersHeadlessSDK.shared.writeLogsToFile(_:debugLog:)

Parameters:

  • enable: enable write logs to file.
  • debugLog: enable write debug logs to file. Default status is false.

Set Environment for OneTrust worker

This API will set the environment of the OT SDK worker configuration.

Parameter:

  • environment: The environment for which the application should be set up for.
  • Values: dev, qa or prod.
OTPublishersHeadlessSDK.shared.setEnviroment(_:)

Note: By default, the environment is set to production.

Clearing OneTrust SDK data

This API will clear all OneTrust SDK data by removing stored UserDefaults, resetting user consent, and resetting all public method values to defaults.

OTPublishersHeadlessSDK.shared.clearOTSDKData()

Set Custom data download URL

This API will set the URL used for fetching the OT SDK data.

Parameter:

  • urlString: URL string value.
OTPublishersHeadlessSDK.shared.setFetchDataURL(_:)

Reading existing Banner Data

Retrieves all the data needed to construct the OT SDK Banner UI.

Note: The keys will not be the same when CMP API is enabled vs disabled.

OTPublishersHeadlessSDK.shared.getBannerData() -> [String: Any]?

Reading existing Preference Center Data

Retrieves all the data needed to construct the OT SDK Preference Center UI.

Note: The keys will not be the same when CMP API is enabled vs disabled.

OTPublishersHeadlessSDK.shared.getPreferenceCenterData() -> [String: Any]?

New (Starting 202504.1.0)

Fetching and reading Banner Data from CMP API flow

This method can be used to trigger a network call to download Banner data from CMP API.

Parameter

  • completion: The completion contains the banner response represented as a dictionary.

Note: If the data is already fetched, the network call will not be made.

OTPublishersHeadlessSDK.shared.fetchBannerCmpApiData(completion:)

Fetching and reading Preference Center Data from CMP API flow

This method can be used to trigger a network call to download Preference Center data from CMP API.

Parameter

  • completion: The completion contains the Preference Center response represented as a dictionary.

Note: If the data is already fetched, the network call will not be made.

OTPublishersHeadlessSDK.shared.fetchPreferencesCmpApiData(completion:

Fetching and reading Vendors Data from CMP API flow

This method retrieves the Vendors data from the CMP API.

Parameter

  • completion: The completion contains the Vendors response represented as a dictionary.

Note: If the data is already fetched, the network call will not be made.

OTPublishersHeadlessSDK.shared.fetchVendorsCmpApiData(completion:)

Deprecated (starting 202504.1.0)

Get Domain Group Data

Retrieves the domain data that is part of culture data in the form of a dictionary.

Note: Please make sure that the OT SDK data is downloaded at least once prior to making this API call.

Deprecation Message: This method will be removed in a couple of releases. Moving forward, please refer to the new list of public methods exposed as domain data will no longer be available directly. We will be exposing individual items that are necessary under domain data via new public methods.

OTPublishersHeadlessSDK.shared.getDomainGroupData() -> [String: Any]?

Get Common Data

Retrieves the common data that is part of culture data in the form of a dictionary.

Note: Please make sure that the OT SDK data is downloaded at least once prior to making this API call.

Deprecation Message: This method will be removed in a couple of releases. Moving forward, please refer to the new list of public methods exposed as common data will no longer be available directly. We will be exposing individual items that are necessary under common data via new public methods.

OTPublishersHeadlessSDK.shared.getDomainInfo() -> [String: Any]?

Get Domain Info

Retrieves domain data in the form of a dictionary.

Note: Please make sure that the OT SDK data is downloaded atleast once prior to making this API call.

Deprecation Message: This method will be removed in a couple of releases. Moving forward, please refer to the new list of public methods exposed as domain information will no longer be available directly. We will be exposing individual items that are necessary under domain information data via new public methods.

OTPublishersHeadlessSDK.shared.getDomainInfo() -> [String: Any]?