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

# Multi Profile Consent

# iOS

## Multi Profile Support

Support for multi profiles has been added to OT SDK based on the profileID/DSID. As part of this feature, all the user choices (purposes, categories, vendors and SDK list) and profile specific data (coming down as part of data download) will be stored per profile basis. As a result, whenever a profile ID/DSID is set by an application, that particular profile storage will be loaded.

In order to use Multi Profile consent, you must first enable it in your **Templates** section.

1. Navigate to Cookie Consent > Setup > Templates.
2. Click on the name of the template you want to configure. The **Template Details** screen appears.
3. Select the **Details** tab and enable the **Mobile App Template** setting.
4. Go to the **Banner** tab and select the **Mobile App** option.
5. Click the **edit** icon next to **Multi Profile Consent**.
6. Enable the **Multi Profile Consent** setting.

> 📘
>
> The SDK only supports up to 6 profiles today.

### Default Profile

There will always be a default profile configured by the OneTrust SDK. Whenever DSID/ProfileID is not set by the application, we will load this default profile. At any point, there will be only one such default profile maintained by OT SDK.

### Retrieve Current Profile ID

This method allows you to retrieve the identifier of the current profile.

#### Swift

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

* Returns a string

### Renaming or Overriding Profiles/Data Subject Identifier

By default, the OneTrust SDK logs a user's consent anonymously under a random GUID. The ID and consent is stored locally on the device as well as in the OneTrust database (if the consent logging toggle is enabled in your geolocation rules).

The following method can be used to rename a profile from one DSID/Profile ID to another.

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

* `from`: The current identifier of the profile. If no profile identifier is passed (e.g. `nil`), the current profile identifier will be updated to new identifier.
* `to`: The new identifier of the profile.
* `withIdentifierType`: Optional, only used when Unified Profile is in scope
* The completion block will be triggered once the rename operation is complete and returns a boolean
* Ensure that the new DSID is unique and does not already exist.
* Ensure that startSDK() has been called at least once.

This method will only rename the profile ID stored locally on the device. The ID stored in the OneTrust Consent database will not update until the user interacts with the CMP again. If you want to have the ID stored in the consent database to be updated right away (without interaction from the user), the recommendation is to to call **saveConsent()** after **renameProfile**. This will commit the user's consent choices again and create a new receipt.

`OTPublishersHeadlessSDK.shared.saveConsent(type: .preferenceCenterConfirm)`

> 📘
>
> If Multi Profile is not in use and you would like to just rename the ID, you must then also pass the identifier into **OTProfileSyncParams** and **startSDK**. Example code snippet below:

```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)")
}
```

### Switching Profiles

Profile switching will happen in the following scenarios:

* Whenever **startSDK()** is called, we will be checking for the profileID/DataSubjectID that will be passed as part of sdkParams object. If this identifier is empty, we will be switching to/loading the default profile maintained by OT SDK.
* Whenever **switchProfile()** is called, we will be checking to see if the data is available for switching a profile. If it is available, we will switch to the passed in profile.
* If an empty identifier is passed, we will be loading the default profile maintained by OT SDK.
  * For data availability, we check if culture data, common data and domain data are available locally for all profiles.
  * If cross device sync enabled scenarios, along with the above data, we will also check if profile data is available locally.
  * For above two conditions to be met, ensure that **startSDK()** is called at least once for an application ID before calling the switchProfile API.

> 📘
>
> Switching profiles when cross device sync is enabled is not supported yet.

#### Swift

```swift
OTPublishersHeadlessSDK.shared.switchProfile(to: "profileIDToBeSwitchedTo", completion: {profileSwitchError in print(profileSwitchError ?? "Profile Switch Successful.") } )
```

* `to`: The identifier of the profile to be loaded.
* `completion`: The completion block that will be triggered at the end of the profile switch operation.

### Deleting Profile

Use the method **deleteProfile()** to delete a profile. If the profile being deleted is currently active, we switch the active profile to default profile and then delete it.

> 📘
>
> Ensure that `startSDK()` is called at least once for an application ID before calling the deleteProfile API.

#### Swift

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

* `profileID`: The identifier of the profile to be deleted.
* `completion`: The completion block that will be triggered after deleting a profile.

Whenever the `OTPublisherHeadlessSDK.shared.clearOTSDKData()` method is called, all the stored profiles and their storages will be deleted along with the SDK storage.