API Reference

Overview

Active Methods

Get Domain Info

This method returns a dictionary containing all the information about the domain (application) including rulesets and template configurations.

// Swift
OTPublishersHeadlessSDK.shared.getDomainInfo()

// ObjC
[OTPublishersHeadlessSDK.shared getDomainInfo];

Get Common Data

This method returns a dictionary which contains template based information like branding which includes keys for determining colors and styles in the UI specific to a template configured for the user's geolocation along with consent logging information.

// Swift
OTPublishersHeadlessSDK.shared.getCommonData()

// ObjC
[OTPublishersHeadlessSDK.shared getCommonData];

Get Groups Data

This method returns a dictionary containing the information about all the categories and sdk IDs specific to a template configured for the user's geolocation.

// Swift
OTPublishersHeadlessSDK.shared.getDomainGroupData()

// ObjC
[OTPublishersHeadlessSDK.shared getDomainGroupData];

Get Banner Data

This method returns a dictionary which contains all the keys required to render a banner.

// Swift
OTPublishersHeadlessSDK.shared.getBannerData()

// ObjC
[OTPublishersHeadlessSDK.shared getBannerData];

Banner Allow All

Call this method when user selects Allow All button on the Banner. This will opt-in the user to all Category/Purposes.

// Swift
OTPublishersHeadlessSDK.shared.saveConsent(type: .bannerAllowAll)

// ObjC
[OTPublishersHeadlessSDK.shared saveConsentWithType:OTConsentInteractionTypeBannerAllowAll]; 

IAB TCF2

For IAB TCF2 templates, this method also sets the values of IAB Purposes, Legitimate Interests (if any), Special Features (if any), Vendor Purpose Consent, and Vendor Purpose Legitimate Interest (if any) to opt-in. These values will be encoded into the TC String and saved to UserDefaults.

Banner Reject All

Call this method when user selects Reject All button on the Banner. This will opt-out the user to all Category/Purposes.

// Swift
OTPublishersHeadlessSDK.shared.saveConsent(type: .bannerRejectAll)

// ObjC
[OTPublishersHeadlessSDK.shared saveConsentWithType:OTConsentInteractionTypeBannerRejectAll]; 

IAB TCF2

For IAB TCF2 templates, this method also updates the values of IAB Purposes, Legitimate Interests (if any), Special Features (if any), Vendor Purpose Consent, and Vendor Purpose Legitimate Interest (if any) to opt-out. These values will be encoded into the TC String and saved to UserDefaults.

Banner Close

Call this method when closing the Banner. It will save the default consent values for each Category/Purpose based on the geolocation rule.

// Swift
OTPublishersHeadlessSDK.shared.saveConsent(type: .bannerClose)

// ObjC
[OTPublishersHeadlessSDK.shared saveDefaultConsentValues]; 

IAB TCF2

For IAB TCF2 templates, this method also updates the values of IAB Purposes, Legitimate Interests (if any), Special Features (if any), Vendor Purpose Consent, and Vendor Purpose Legitimate Interest (if any). These values will be encoded into the TC String and saved to UserDefaults.

Get Preference Center Data

This method returns a dictionary which contains all the keys required to render a Preference Center.

// Swift
OTPublishersHeadlessSDK.shared.getPreferenceCenterData()

// ObjC
[OTPublishersHeadlessSDK.shared getPreferenceCenterData];

Preference Center Allow All

Call this method when user selects Allow All button on the Banner. This will opt-in the user to all Category/Purposes.

// Swift
OTPublishersHeadlessSDK.shared.saveConsent(type: .preferenceCenterAllowAll)

// ObjC
[OTPublishersHeadlessSDK.shared saveConsentWithType:OTConsentInteractionTypePreferenceCenterAllowAll]; 

IAB TCF2

For IAB TCF2 templates, this method also sets the values of IAB Purposes, Legitimate Interests (if any), Special Features (if any), Vendor Purpose Consent, and Vendor Purpose Legitimate Interest (if any) to opt-in. These values will be encoded into the TC String and saved to UserDefaults.

Preference Center Reject All

Call this method when user selects Reject All button on the Banner. This will opt-out the user to all Category/Purposes.

// Swift
OTPublishersHeadlessSDK.shared.saveConsent(type: .preferenceCenterRejectAll)

// ObjC
[OTPublishersHeadlessSDK.shared saveConsentWithType:OTConsentInteractionTypePreferenceCenterRejectAll]; 

IAB TCF2

For IAB TCF2 templates, this method also updates the values of IAB Purposes, Legitimate Interests (if any), Special Features (if any), Vendor Purpose Consent, and Vendor Purpose Legitimate Interest (if any) to opt-out. These values will be encoded into the TC String and saved to UserDefaults.

Programmatically Update and Save Purpose Consent

These methods are typically utilized in a BYOUI approach and can be used to update and save consent programmatically for a specific category to true or false based on user input. Simply pass in the group/category ID and consent status to update the values.

Usage

Modifying the user's consent is a two step approach. updatePurposeConsent() is used to set the state of the consent (toggles) on the UI and saveConsent() is used to commit and save the consent to local storage. saveConsent MUST be called or consent will NOT be committed and changed.

// Swift
OTPublishersHeadlessSDK.shared.updatePurposeConsent(forGroup: "C0004", consentValue: true, updateHierarchy: true)
OTPublishersHeadlessSDK.shared.updatePurposeConsent(forGroup: "C0002", consentValue: false, updateHierarchy: true)
// Swift
OTPublishersHeadlessSDK.shared.saveConsent(type: .preferenceCenterConfirm)

Parameters

  • forGroup - Category/Group ID of the category to be modified (e.g. C0001, C0002, C0004, etc.)
  • consentValue - Consent status given by the user for a category/group. Boolean type.
  • updateHierarchy - Updates the toggle state on the OneTrust UI
  • type - Denotes the type of interaction used to commit/save consent (e.g. banner allow all, preference center confirm, preference center reject, etc.)

Below is a sample implementation on how to update and save if you have multiple categories to update at a time.

// Swift
OTPublishersHeadlessSDK.shared.updatePurposeConsent(forGroup: "C0004", consentValue: true, updateHierarchy: true)
OTPublishersHeadlessSDK.shared.updatePurposeConsent(forGroup: "C0005", consentValue: true, updateHierarchy: true)
OTPublishersHeadlessSDK.shared.updatePurposeConsent(forGroup: "C0006", consentValue: true, updateHierarchy: true)
OTPublishersHeadlessSDK.shared.updatePurposeConsent(forGroup: "IABV2_6", consentValue: true, updateHierarchy: true)
OTPublishersHeadlessSDK.shared.saveConsent(type: .preferenceCenterConfirm)

Reset updated consent values for all Categories

This method resets any updated Category/Purpose consent values to their defaults prior to being saved to disk. Use this method if a user makes updates in their Preference Center but then exits without Saving their choices.

// Swift
OTPublishersHeadlessSDK.shared.resetUpdatedConsent()

/// ObjC
[OTPublishersHeadlessSDK.shared resetUpdatedConsent];

Get Vendor List UI

This method will allow your application to retrieve the dictionary required to render the vendor list UI. It returns a dictionary containing local state of active IAB Vendor List if values are updated without save using updateVendorConsent/updateVendorLegitInterest. Returns previously saved IAB vendor state if nothing has changed. Nil if no active vendors are found.

// Swift
OTPublishersHeadlessSDK.shared.getVendorListUI()

// ObjC
[OTPublishersHeadlessSDK.shared getVendorListUI];

Get Vendor List Data

This method will allow your application to retrieve the dictionary required to render the vendor list UI. It returns a dictionary containing saved state of active IAB Vendor List. Returns nil if no active vendors are found.

// Swift
OTPublishersHeadlessSDK.shared.getVendorListData()

// ObjC
[OTPublishersHeadlessSDK.shared getVendorListData];

Get Total Vendor Count

This method allows you to return the total number of IAB TCF vendors your app is using. This can be useful in instances where you're building your own banner and need to include the vendor count as required by IAB.

var vendorCount = OTPublishersHeadlessSDK.shared.getVendorListData(for: VendorListMode.iab)
vendorCount?.count

Query Consent Status for a Category

Query the current consent status for any of the Categories included in your application. This can be used to determine what privacy action is needed at app launch or anytime the consent status is needed without being notified by an event broadcast. Simply pass in the Category ID (eg. C0001) and the method will return the current consent status.

// Swift
OTPublishersHeadlessSDK.shared.getConsentStatus(forCategory: "C0002")

// ObjC
[OTPublishersHeadlessSDK.shared getConsentStatusForCategory:@"C0002"];

Parameters

  • forCategory - Custom group ID contained in the group dictionary returned by SDK public methods. Custom group IDs for each category can be obtained from OneTrust console as well.

Returns

  • 1 = Consent Given
  • 0 = Consent Not Given
  • -1 = Consent has not been collected/ sdk is not yet initialized

Query Consent Status for a Specific SDK

Query the current consent status for any of the SDKs included in your application. This can be used to determine what privacy action is needed at application launch or anytime the consent status is needed without being notified by an event broadcast. Pass in the SDK ID and the method will return the current consent status.

// Swift
OTPublishersHeadlessSDK.shared.getConsentStatus(forSDKId: "2368810c-94da-4f18-ab92-c55c5f74cca9")

// ObjC
[OTPublishersHeadlessSDK.shared getConsentStatusForSDKId:@"2368810c-94da-4f18-ab92-c55c5f74cca9"];

Parameters

  • SDK GUID - SDK ID contained in the group dictionary returned by SDK public methods. SDK IDs for each SDK configured in the application can be obtained from OneTrust console as well.

Returns

  • 1 = Consent Given
  • 0 = Consent Not Given
  • -1 = Consent has not been collected

Set Data Subject Identifier

This method sets the identifier for the User Profile the consent is being saved to.

  • When the identifier is not set, the SDK will generate a unique (anonymous) identifier by default.
Requires SDK Init?Yes
MethodOTPublishersHeadlessSDK.shared.renameProfile(from: "currentProfileID", to: "newProfileID",completion: { renameSuccess in print(renameSuccess) } )
Argumentsid: string

After renaming the user ID, you must pass the identifier into OTProfileSyncParams and startSDK.

OTPublishersHeadlessSDK.shared.renameProfile(to: "[email protected]") { Bool in
    print("Rename complete")
}

let sdkParams = OTSdkParams(countryCode: nil, regionCode: nil)
let profileSyncParams = OTProfileSyncParams()
profileSyncParams.setIdentifier(OTPublishersHeadlessSDK.shared.currentActiveProfile)
sdkParams.setProfileSyncParams(profileSyncParams)


OTPublishersHeadlessSDK.shared.startSDK(storageLocation: cdnLocation, domainIdentifier: appID,
                                        languageCode: lang,
                                        params: sdkParams) { [weak self] response in
                                        
      guard let self = self, let _ = response.error else { return }
      print("Current DSID = \(OTPublishersHeadlessSDK.shared.currentActiveProfile)")
}

Get Data Subject Identifier

This method returns the Data Subject ID saved by the SDK. You can use this value to lookup Consent Receipts for a User on the OneTrust Admin.

Requires SDK Init?Yes
MethodOTPublishersHeadlessSDK.shared.currentActiveProfile
Argumentsn/a
Returnsstring

Should Show Banner

This method will inform your application if the OneTrust Banner has to be presented to the user or not for the user's current location. This method will return true or false based on the geolocation configurations you have assigned for the application in OneTrust environment.
This can be used by your app to determine if functions to build and display UI have to be called.

// Swift
OTPublishersHeadlessSDK.shared.shouldShowBanner()

// ObjC
[OTPublishersHeadlessSDK.shared shouldShowBanner];

Returns

  • true - show banner for that geolocation
  • false - don't show banner for user's geolocation / consent has been taken already.

Clear SDK Data

This method will delete all the data saved in the SDK. When application calls this method, SDK will:

  • Clear all values saved in UserDefaults
  • Clear all previously given user consent values, if any
  • Reset all public method values to defaults
// Swift
OTPublishersHeadlessSDK.shared.clearOTSDKData() 

//ObjC 
[OTPublishersHeadlessSDK.shared clearOTSDKData];

Multi Profile Consent

The following methods can be used to support multi profile consent for your application if you allow multiple user profiles to use one login.

  • Use the following method to allow users to switch profiles so that consent profile of the current user is saved and profile for the new user is retrieved from user defaults.
OTPublishersHeadlessSDK.shared.switchProfile(to "profileIDToBeSwitchedTo", completion: {profileSwitchError in print(profileSwitchError ?? "Profile Switch Successful.") } )
  • Use the following method to allow you to rename a user's profile.
OTPublishersHeadlessSDK.shared.renameProfile(from: "currentProfileID", to: "newProfileID",completion: { renameSuccess in print(renameSuccess) } ) 
  • Use the following method to delete a user's profile.
OTPublishersHeadlessSDK.shared.deleteProfile("profileIDToBeDeleted", completion: { deletionError in print(deletionError ?? "Profile Deletion Successful.") } )
  • Use the following method to retrieve the current profile ID.
OTPublishersHeadlessSDK.shared.currentActiveProfile

Deprecated Methods

acceptAll()

MethodSwift: OTPublishersHeadlessSDK.shared.acceptAll()
ObjC: [OTPublishersHeadlessSDK.shared acceptAll];
DescriptionMethod connected with the Accept All button for both Banner and Preference Center.
ReasonWe are shifting to a more flexible approach using saveConsent(type: ). This gives more flexibility for capturing advanced analytics in future.
Deprecated Version6.10.0
Migrate ToApplications should migrate to using either:
saveConsent(type: .bannerAllowAll)
saveConsent(type: .preferenceCenterAllowAll)

rejectAll()

MethodSwift: OTPublishersHeadlessSDK.shared.rejectAll()
ObjC: [OTPublishersHeadlessSDK.shared rejectAll];
DescriptionMethod connected with the Reject All button for both Banner and Preference Center.
ReasonWe are shifting to a more flexible approach using saveConsent(type: ). This gives more flexibility for capturing advanced analytics in future.
Deprecated Version6.10.0
Migrate ToApplications should migrate to using either:
saveConsent(type: .bannerRejectAll)
saveConsent(type: .preferenceCenterRejectAll)

saveDefaultConsentValue()

MethodSwift: OTPublishersHeadlessSDK.shared.saveDefaultConsentValue()
ObjC: [OTPublishersHeadlessSDK.shared saveDefaultConsentValue];
DescriptionMethod used when a user Closes the Banner and the default consent for the geolocation is saved to disk.
ReasonWe are shifting to a more flexible approach using saveConsent(type: ). This gives more flexibility for capturing advanced analytics in future.
Deprecated Version6.10.0
Migrate ToApplications should migrate to using saveConsent(type: .bannerClose)

saveConsentValue()

MethodSwift: OTPublishersHeadlessSDK.shared.saveConsentValue()
ObjC: [OTPublishersHeadlessSDK.shared saveConsentValue];
DescriptionMethod for saving Category/Purpose consent status changes to disk once they've been updated with updatePurposeConsent(forGroup: , consentValue: ).
ReasonWe are shifting to a more flexible approach using saveConsent(type: ). This gives more flexibility for capturing advanced analytics in future.
Deprecated Version6.10.0
Migrate ToApplications should migrate to using saveConsent(type: .preferenceCenterConfirm)

initOTSDKData

MethodSwift: OTPublishersHeadlessSDK.shared.initOTSDKData()
ObjC: [OTPublishersHeadlessSDK.shared initOTSDKData];
DescriptionThe way the SDK initializes.
ReasonWe are moving away from storing the entire JSON response as a part of this method, and instead will be returning a new OTResponse object in case the application needs to save the entire JSON response.
Deprecated Version6.15.0
Migrate ToApplications should migrate to using startSDK()

getOTSDKData

MethodSwift: OTPublishersHeadlessSDK.shared.getOTSDKData()
ObjC: [OTPublishersHeadlessSDK.shared getOTSDKData];
DescriptionAllows application to access full JSON data payload.
ReasonWe are moving away from storing the entire JSON response in string format in User Defaults. Instead, we will be storing cultureData, domainData, and profile separately.
Deprecated Version6.15.0
Migrate ToApplications should migrate to using either:
getDomainGroupData()
getDomainInfo()
getCommonData()

setDataSubjectIdentifier

MethodSwift: OTPublishersHeadlessSDK.shared.cache.dataSubjectIdentifier
ObjC: [OTPublishersHeadlessSDK.shared setDataSubjectIdentifier:@"User Identifier"];
DescriptionSets the identifier for the User Profile the consent is being saved to.
ReasonThis method has been replaced by renameProfile()
Deprecated Version6.34.0
Migrate ToApplications should migrate to using:
renameProfile()

getDataSubjectIdentifier

MethodSwift: OTPublishersHeadlessSDK.shared.cache.dataSubjectIdentifier
DescriptionReturns the Data Subject ID saved by the SDK. You can use this value to lookup Consent Receipts for a User on the OneTrust Admin.
ReasonThis method has been replaced by currentActiveProfile()
Deprecated Version6.34.0
Migrate ToApplications should migrate to using:
currentActiveProfile()

Override Data subject Identifier

OneTrust SDK logs consent transactions based on consent logging feature that have been enabled in OneTrust's environment. By default, consent logging feature will generate a unique identifier for each device and log transactions considering it as an anonymous user.
OneTrust provides a method to override this randomly generated identifier by passing a valid String value for identifier variable. This method will set the value to SDK and show as the Data Subject Identifier in OneTrust environment while reviewing transactions. This method MUST be called after initializing the SDK.
If the identifier is set after user giving consent, then the last anonymous transaction and the subsequent transactions will be logged with the new identifier set by your application.

// Swift
OTPublishersHeadlessSDK.shared.overrideDataSubjectIdentifier("userId")

// ObjC
[OTPublishersHeadlessSDK.shared overrideDataSubjectIdentifier:@"userId"];

Parameters

  • Data Subject Identifier - a valid String value.