API Reference

This section is a comprehensive reference to the Xamarin SDK and the methods that can be called to initialize, manage, and interact with consent data.

Always use CMPSDK.sharedInstance to refer to the OneTrust SDK. Please verify the SDK successfully initializes before calling any of these methods. (see Initialize the SDK).


Retrieve data to build your UI

MethodData Retrieved
CMPSDK.sharedInstance.dataForBanner();JSON to build banner
CMPSDK.sharedInstance.dataForPreferenceCenter();JSON to build preference center
CMPSDK.sharedInstance.groupsDataForUIBinding();JSON to populate preference center with Category/Group data
CMPSDK.sharedInstance.getSavedConsentProfile()JSON object with the saved state of the categories
CMPSDK.sharedInstance.dataForVendorList();JSON to build vendor list (TCF 2.0 use cases only)

Handling user interactions

Banner

Method NameUsage
CMPSDK.sharedInstance.bannerAccept();User has clicked "Accept All" on banner
CMPSDK.sharedInstance.bannerRejectAll();User has clicked "Reject All" on banner
CMPSDK.sharedInstance.bannerClose();User has closed the banner

Preference Center

When updating consents for individual categories, the Preference Center works on a "stage and commit" model. You will update the consent values for each category as it is toggled, but changes will not be saved until the Save function is called.

Method NameUsage
CMPSDK.sharedInstance.updateConsentValueForCategory(string category, bool consentValue);User has adjusted a consent toggle
CMPSDK.sharedInstance.saveChanges();User has saved changes in the preference center
CMPSDK.sharedInstance.preferenceCenterAcceptAll();User has accepted all in the preference center - there is no need to save after this is called
CMPSDK.sharedInstance.preferenceCenterRejectAll();User has rejected all in the preference center - there is no need to save after this is called

Vendor List

When updating consents for individual vendors, the vendor list works on a "stage and commit" model. You will update the consent values for each vendor consent as it is toggled, but changes will not be saved until the Save function is called.

Method NameUsage
CMPSDK.sharedInstance.updateConsentValueForVendor(string vendorId, bool consentValue);User has adjusted a consent toggle
CMPSDK.sharedInstance.updateConsentValueForVendorLegitimateInterest(string vendorId, bool consentValue);User has adjusted a LegitimateInterest toggle
CMPSDK.sharedInstance.saveChanges();User has saved changes in the preference center
CMPSDK.sharedInstance.vendorsAcceptAll();User has accepted all in the vendor list - there is no need to save after this is called
CMPSDK.sharedInstance.vendorsRejectAll();User has rejected all in the vendor list - there is no need to save after this is called

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.

Method Name
CMPSDK.sharedInstance.userProfiles()Call this to list the user profiles.
CMPSDK.sharedInstance.switchUserProfile(DSID)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.
CMPSDK.sharedInstance.renameProfile(from: old_profile_id, to: new_profile_ID)Use the following method to allow you to rename a user's profile.
CMPSDK.sharedInstance.deleteProfile(dsid)Use the following method to delete a user's profile.

userProfiles Payload

// Returns array of profiles.  Only 1 profile can be Active.
[
  {
    "OneTrust_ConsentLoggingIdentifier": "545bd599-51d6-401e-af1c-17c0611ad81f",
    "OneTrust_UID_isAnonymous": true,
    "OneTrust_lastInteraction": "Preference Center - Confirm",
    "OneTrust_lastConsentDate": 637902346597025080,
    "isActiveProfile": true
	},
  {
    "OneTrust_ConsentLoggingIdentifier": "9898db3-51d6-401e-af1c-17c0611ad37d",
    "OneTrust_UID_isAnonymous": true,
    "OneTrust_lastInteraction": "Banner - Accept All",
    "OneTrust_lastConsentDate": 637902346597025080,
    "isActiveProfile": false
	}
]
// If you want to take lastConsentDate to a formatted date...

DateTime lastConsentDate = new DateTime(long.Parse(OneTrust_lastConsentDate));
System.Diagnostics.Debug.WriteLine(lastConsentDate.ToUniversalTime().ToString("F"));