> ## Documentation Index
> Fetch the complete documentation index at: https://developer.onetrust.com/llms.txt
> Use this file to discover all available pages before exploring further.

# API Reference

OneTrust iOS SDK Public Methods

## Active Methods

### Get Domain Info

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

```swift
// 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
// 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
// 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
// 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
// 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
// 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
// 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
// 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
// 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
// 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
// Swift
OTPublishersHeadlessSDK.shared.updatePurposeConsent(forGroup: "C0004", consentValue: true, updateHierarchy: true)
OTPublishersHeadlessSDK.shared.updatePurposeConsent(forGroup: "C0002", consentValue: false, updateHierarchy: true)
```

```swift
// 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
// 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
// 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
// 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
// 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.

```swift
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
// 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
// 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.

[block:parameters]
{
  "data": {
    "h-0": "<span style=\"font-weight: bold\">Requires SDK Init?</span>",
    "h-1": "<span style=\"font-weight: normal\">Yes</span>",
    "0-0": "<span style=\"font-weight: bold\">Method</span>",
    "0-1": "`OTPublishersHeadlessSDK.shared.renameProfile(from: \"currentProfileID\", to: \"newProfileID\",completion: { renameSuccess in print(renameSuccess) } ) `",
    "1-0": "<span style=\"font-weight: bold\">Arguments</span>",
    "1-1": "id: `string`"
  },
  "cols": 2,
  "rows": 2,
  "align": [
    null,
    null
  ]
}
[/block]

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

```swift
OTPublishersHeadlessSDK.shared.renameProfile(to: "user@email.com") { 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.

[block:parameters]
{
  "data": {
    "h-0": "<span style=\"font-weight: bold\">Requires SDK Init?</span>",
    "h-1": "<span style=\"font-weight: normal\">Yes</span>",
    "0-0": "<span style=\"font-weight: bold\">Method</span>",
    "0-1": "<span style=\"font-weight: normal\">`OTPublishersHeadlessSDK.shared.currentActiveProfile`</span>",
    "1-0": "<span style=\"font-weight: bold\">Arguments</span>",
    "1-1": "n/a",
    "2-0": "<span style=\"font-weight: bold\">Returns</span>",
    "2-1": "`string`"
  },
  "cols": 2,
  "rows": 3,
  "align": [
    null,
    null
  ]
}
[/block]

### 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
// 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
// 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.

```swift
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.

```swift
OTPublishersHeadlessSDK.shared.renameProfile(from: "currentProfileID", to: "newProfileID",completion: { renameSuccess in print(renameSuccess) } ) 
```

* Use the following method to delete a user's profile.

```swift
OTPublishersHeadlessSDK.shared.deleteProfile("profileIDToBeDeleted", completion: { deletionError in print(deletionError ?? "Profile Deletion Successful.") } )
```

* Use the following method to retrieve the current profile ID.

```swift
OTPublishersHeadlessSDK.shared.currentActiveProfile
```

## Deprecated Methods

### `acceptAll()`

[block:parameters]
{
  "data": {
    "h-0": "**Method**",
    "h-1": "<span style=\"font-weight:normal\">Swift: `OTPublishersHeadlessSDK.shared.acceptAll()` <br> ObjC: `[OTPublishersHeadlessSDK.shared acceptAll];`</span>",
    "0-0": "**Description**",
    "0-1": "Method connected with the Accept All button for both Banner and Preference Center.",
    "1-0": "**Reason**",
    "1-1": "We are shifting to a more flexible approach using `saveConsent(type: )`.  This gives more flexibility for capturing advanced analytics in future.",
    "2-0": "**Deprecated Version**",
    "2-1": "6.10.0",
    "3-0": "**Migrate To**",
    "3-1": "Applications should migrate to using either: <br> [saveConsent(type: .bannerAllowAll)](https://developer.onetrust.com/sdk/mobile-apps/ios/byoui/#banner-allow-all) <br> [saveConsent(type: .preferenceCenterAllowAll)](https://developer.onetrust.com/sdk/mobile-apps/ios/byoui/#preference-center-allow-all)"
  },
  "cols": 2,
  "rows": 4,
  "align": [
    null,
    null
  ]
}
[/block]

<br />

### `rejectAll()`

[block:parameters]
{
  "data": {
    "h-0": "**Method**",
    "h-1": "<span style=\"font-weight:normal\">Swift: `OTPublishersHeadlessSDK.shared.rejectAll()` <br> ObjC: `[OTPublishersHeadlessSDK.shared rejectAll];`</span>",
    "0-0": "**Description**",
    "0-1": "Method connected with the Reject All button for both Banner and Preference Center.",
    "1-0": "**Reason**",
    "1-1": "We are shifting to a more flexible approach using `saveConsent(type: )`.  This gives more flexibility for capturing advanced analytics in future.",
    "2-0": "**Deprecated Version**",
    "2-1": "6.10.0",
    "3-0": "**Migrate To**",
    "3-1": "Applications should migrate to using either: <br> [saveConsent(type: .bannerRejectAll)](https://developer.onetrust.com/sdk/mobile-apps/ios/byoui/#banner-reject-all) <br> [saveConsent(type: .preferenceCenterRejectAll)](https://developer.onetrust.com/sdk/mobile-apps/ios/byoui/#preference-center-reject-all)"
  },
  "cols": 2,
  "rows": 4,
  "align": [
    null,
    null
  ]
}
[/block]

<br />

### `saveDefaultConsentValue()`

[block:parameters]
{
  "data": {
    "h-0": "**Method**",
    "h-1": "<span style=\"font-weight:normal\">Swift: `OTPublishersHeadlessSDK.shared.saveDefaultConsentValue()` <br> ObjC: `[OTPublishersHeadlessSDK.shared saveDefaultConsentValue];`</span>",
    "0-0": "**Description**",
    "0-1": "Method used when a user Closes the Banner and the default consent for the geolocation is saved to disk.",
    "1-0": "**Reason**",
    "1-1": "We are shifting to a more flexible approach using `saveConsent(type: )`.  This gives more flexibility for capturing advanced analytics in future.",
    "2-0": "**Deprecated Version**",
    "2-1": "6.10.0",
    "3-0": "**Migrate To**",
    "3-1": "Applications should migrate to using [saveConsent(type: .bannerClose)](https://developer.onetrust.com/sdk/mobile-apps/ios/byoui#banner-close)"
  },
  "cols": 2,
  "rows": 4,
  "align": [
    null,
    null
  ]
}
[/block]

<br />

### `saveConsentValue()`

[block:parameters]
{
  "data": {
    "h-0": "**Method**",
    "h-1": "<span style=\"font-weight:normal\">Swift: `OTPublishersHeadlessSDK.shared.saveConsentValue()` <br> ObjC: `[OTPublishersHeadlessSDK.shared saveConsentValue];`</span>",
    "0-0": "**Description**",
    "0-1": "Method for saving Category/Purpose consent status changes to disk once they've been updated with `updatePurposeConsent(forGroup: , consentValue: )`.",
    "1-0": "**Reason**",
    "1-1": "We are shifting to a more flexible approach using `saveConsent(type: )`.  This gives more flexibility for capturing advanced analytics in future.",
    "2-0": "**Deprecated Version**",
    "2-1": "6.10.0",
    "3-0": "**Migrate To**",
    "3-1": "Applications should migrate to using [saveConsent(type: .preferenceCenterConfirm)](https://developer.onetrust.com/sdk/mobile-apps/ios/byoui#preference-center-update-and-save-purpose-consent)"
  },
  "cols": 2,
  "rows": 4,
  "align": [
    null,
    null
  ]
}
[/block]

### `initOTSDKData`

[block:parameters]
{
  "data": {
    "h-0": "**Method**",
    "h-1": "<span style=\"font-weight:normal\">Swift: `OTPublishersHeadlessSDK.shared.initOTSDKData()` <br> ObjC: `[OTPublishersHeadlessSDK.shared initOTSDKData];`</span>",
    "0-0": "**Description**",
    "0-1": "The way the SDK initializes.",
    "1-0": "**Reason**",
    "1-1": "We 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.",
    "2-0": "**Deprecated Version**",
    "2-1": "6.15.0",
    "3-0": "**Migrate To**",
    "3-1": "Applications should migrate to using [startSDK()](https://developer.onetrust.com/sdk/mobile-apps/ios/init-sdk#startSDK)"
  },
  "cols": 2,
  "rows": 4,
  "align": [
    null,
    null
  ]
}
[/block]

### `getOTSDKData`

[block:parameters]
{
  "data": {
    "h-0": "**Method**",
    "h-1": "<span style=\"font-weight:normal\">Swift: `OTPublishersHeadlessSDK.shared.getOTSDKData()` <br> ObjC: `[OTPublishersHeadlessSDK.shared getOTSDKData];`</span>",
    "0-0": "**Description**",
    "0-1": "Allows application to access full JSON data payload.",
    "1-0": "**Reason**",
    "1-1": "We 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.",
    "2-0": "**Deprecated Version**",
    "2-1": "6.15.0",
    "3-0": "**Migrate To**",
    "3-1": "Applications should migrate to using either: <br> [getDomainGroupData()](https://developer.onetrust.com/sdk/mobile-apps/ios/byoui#get-groups-data) <br> [getDomainInfo()](https://developer.onetrust.com/sdk/mobile-apps/ios/byoui#get-domain-info) <br> [getCommonData()](https://developer.onetrust.com/sdk/mobile-apps/ios/byoui#get-common-data)"
  },
  "cols": 2,
  "rows": 4,
  "align": [
    null,
    null
  ]
}
[/block]

### `setDataSubjectIdentifier`

[block:parameters]
{
  "data": {
    "h-0": "**Method**",
    "h-1": "<span style=\"font-weight:normal\">Swift: `OTPublishersHeadlessSDK.shared.cache.dataSubjectIdentifier` <br> ObjC: `[OTPublishersHeadlessSDK.shared setDataSubjectIdentifier:@\"User Identifier\"];`</span>",
    "0-0": "**Description**",
    "0-1": "Sets the identifier for the User Profile the consent is being saved to.",
    "1-0": "**Reason**",
    "1-1": "This method has been replaced by renameProfile()",
    "2-0": "**Deprecated Version**",
    "2-1": "6.34.0",
    "3-0": "**Migrate To**",
    "3-1": "Applications should migrate to using: <br> [renameProfile()](https://developer.onetrust.com/onetrust/docs/multi-profile-consent-ios#renamingoverriding-profilesdata-subject-identifier)"
  },
  "cols": 2,
  "rows": 4,
  "align": [
    null,
    null
  ]
}
[/block]

### `getDataSubjectIdentifier`

[block:parameters]
{
  "data": {
    "h-0": "**Method**",
    "h-1": "<span style=\"font-weight:normal\">Swift: `OTPublishersHeadlessSDK.shared.cache.dataSubjectIdentifier` </span>",
    "0-0": "**Description**",
    "0-1": "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.",
    "1-0": "**Reason**",
    "1-1": "This method has been replaced by currentActiveProfile()",
    "2-0": "**Deprecated Version**",
    "2-1": "6.34.0",
    "3-0": "**Migrate To**",
    "3-1": "Applications should migrate to using: <br> currentActiveProfile()"
  },
  "cols": 2,
  "rows": 4,
  "align": [
    null,
    null
  ]
}
[/block]

### 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
// Swift
OTPublishersHeadlessSDK.shared.overrideDataSubjectIdentifier("userId")

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

#### Parameters

* Data Subject Identifier - a valid String value.