Add SDK to App

Overview

Before You Begin

Prior to implmenting the Xamarin SDK into your Xamarin application, you first need to decide what kind of Xamarin implementation path you need:

  • Xamarin.iOS and Xamarin.Android (Native)
  • Xamarin Forms

Xamarin.iOS and Xamarin.Android Steps

  1. Inside of VisualStudio, right click the References folder inside of your project

  2. Select Add Reference

  3. Select .Net Assembly tab

  4. Select Browse button

  5. Locate the cmpsdk.dll within the OneTrust_CMP_Xamarin_DLL folder

  1. Select cmpsdk.dll file

  1. Select OK button. You should see cmpsdk in your References section.
iOS Example

iOS Example

Android Example

Android Example

  1. For iOS, copy the OneTrustSDK folder from the Xamarin-Native directory and paste into the otsdk.xamarin.iosProject. For Android, do the same with otsdk.xamarin.android.

  1. Navigate to OneTrustSDK > HTML and take note of each of the HTML, CSS, and JS files in that directory. Select one of the files, then navigate to the Build action dropdown under the Properties tab and select BundleResource (iOS) or AndroidAsset (Android) as the option. You will need to do this for each file in this HTML directory.
iOS example using BundleResource

iOS example using BundleResource

Android example using AndroidAsset

Android example using AndroidAsset

Recommendation: Use the Xamarin-Native sample project as a reference for how to communicate with the cmpsdk.dll.

For iOS: Reference the AppDelegate.cs file.

For Android: Reference the MainActivity.cs file.

Xamarin Forms Steps

First, you need to add the OneTrust SDK's dll file to your existing application.

  1. Inside of VisualStudio, right click the References folder inside of your project
  2. Select Add Reference
  3. Select .Net Assembly tab
  4. Select Browse button
  5. Locate the cmpsdk.dll within the OneTrust_CMP_Xamarin_DLL folder
  6. Select cmpsdk.dll file
  7. Select OK button

Since you plan to use the OneTrust UI, you will need to also copy the UI files into your Xamarin shared project.

  1. Navigate to the Xamarin-Forms-With-UI / OTSDK-UI / OneTrustSDK directory in your download.
  2. Copy and Paste that folder into your existing Xamarin shared Project.

There are additional dependencies to inject into your existing application which writes the UserAgent string when a user saves consent. For Xamarin Forms, it's necessary to include these files in your project to avoide build errors.

  1. For iOS, locate the Xamarin-Forms-With-UI / OTSDK-UI.iOS / UserAgentString.cs file and copy it into your project. For Android, the locate both Xamarin-Forms-With-UI / OTSDK-UI.Android / UserAgentString.cs and Xamarin-Forms-With-UI / OTSDK-UI.Android / OneTrustContentViewRenderer.cs files and copy both into your project.

Note: For OneTrust sample app, the shared project name is OTSDK-UI. Your shared project name will be different.

Recommendation: Use the Xamarin-Forms-With-UI sample project as a reference for how to communicate with the cmpsdk.dll.

Additionally, use the MainPage.xaml file to reference how to launch the OneTrust UI.

Add SDK to App for Unity

  1. Download the Unity package from your OneTrust tenant.
  2. In the Unity engine, import a new package and select the OneTrust package from the file explorer.
  3. Import all files.
  4. From here, a demo scene is available with many common use cases.