Additional Information
Additional information on OneTrust iOS SDK public methods
Saving Consent
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)
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)
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)
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()
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)
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)
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 UItype
- 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()
More details about Vendors API
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()
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.
// Prior to 202504.1.0
OTPublishersHeadlessSDK.shared.getVendorListData()
// 202504.1.0 onwards
OTPublishersHeadlessSDK.shared.getAllVendors(mode: .iab)
OTPublishersHeadlessSDK.shared.getAllVendors(mode: .google)
OTPublishersHeadlessSDK.shared.getAllVendors(mode: .general)
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.
// Prior to 202504.1.0
var allVendors = OTPublishersHeadlessSDK.shared.getVendorListData(for: VendorListMode.iab)
allVendors?.count
// 202504.1.0 onwards
OTPublishersHeadlessSDK.shared.getAllVendors(mode: .iab)?.count
OTPublishersHeadlessSDK.shared.getAllVendors(mode: .google)?.count
OTPublishersHeadlessSDK.shared.getAllVendors(mode: .general)?.count
More details about Groups API
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")
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 |
---|---|
Method | OTPublishersHeadlessSDK.shared.renameProfile(from: "currentProfileID", to: "newProfileID",completion: { renameSuccess in print(renameSuccess) } ) |
Arguments | id: 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 |
---|---|
Method | OTPublishersHeadlessSDK.shared.currentActiveProfile |
Arguments | n/a |
Returns | string |
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
Updated 3 days ago