Add SDK to App

Overview

Requires iOS 11.0+ and tvOS 11.0+

Import Methods

iOS

  • Import OneTrust-CMP-XCFramework via Cocoapods (recommended)`
  • Import OTPublishersHeadlessSDK.xcframework directly
  • Import OTPublishersHeadlessSDK.framework directly

tvOS

  • Import OneTrust-CMP-tvOS-XCFramework via Cocoapods (recommended)
  • Import OTPublishersHeadlessSDKtvOS.xcframework directly
  • Import OTPublishersHeadlessSDKtvOS.framework directly

Import via CocoaPods (recommended)

If your app has used a previous version of the SDK prior, remove those frameworks from the application target.

  1. Add Podfile to your Application if using CocoaPod for the first time. Please refer to Cocoapods Documentation for additional guidance.

  2. Edit Podfile to add the Pod name and version of your choice.

iOS

// Install the SDK version that matches the version published
pod 'OneTrust-CMP-XCFramework', '~> X.XX.0.0'

// Example
pod 'OneTrust-CMP-XCFramework', '~> 202209.1.0.0'

tvOS

// Install the SDK version that matches the version published
pod 'OneTrust-CMP-tvOS-XCFramework', '~> X.XX.0.0'

// Example 
pod 'OneTrust-CMP-tvOS-XCFramework', '~> 202209.1.0.0'
  1. Open Terminal, change the working directory to the directory where Podfile resides, and Run pod install.

  2. Open {Application}.xcworkspace file in Xcode

  3. Run the app.


Import OT SDK using Swift Package Manager

If the application target have been using .framework or .xcframework earlier, delete any existance of .framework/.xcframework and all of it's references from Target's Build or General Settings before adopting Swift Package.

  • Delete the existing OTPublishersHeadlessSDK.framework / OTPublishersHeadlessSDK.xcframework (for tvOS OTPublishersHeadlessSDKtvOS.framework / OTPublishersHeadlessSDKtvOS.xcframework) from Application Target.
  • Remove OTPublishersHeadlessSDK.framework / OTPublishersHeadlessSDK.xcframework (for tvOS OTPublishersHeadlessSDKtvOS.framework / OTPublishersHeadlessSDKtvOS.xcframework) from "Embedded Frameworks" and to "Link Binary With Libraries" under Application Target's Build Phases Tab if not automatically removed.
  1. Open the Application project or workspace.
  2. Next, select File -> Add Packages.... This will pop up the Swift Packages screen.
  3. On the top right corner of the Swift Packages pop-up, you can search for Swift Packages. Enter the URL for the corresponding Swift package you want to integrate and press ENTER.
  1. This will now show and select the Swift package in the middle section of the pop-up. On the right side, we will be prompted to decide the Dependency Rule and the Project.
  2. Choose the Dependency Rule that is appropriate for your project and select Exact Version and specify the version of the SDK you'd like to import.
  3. Choose the Project by selecting the Project to which your application target belongs to.
  4. Now on the bottom-right of the pop-up, you will see that the Add Package button is now enabled.
  5. Click on the button. This will now start resolving the Swift package for you.
  6. While resolving the Swift package, you will be prompted with a new pop-up (Choose Package Product) where you will need to select the Target to which the Swift Package Product should be added to.
  7. Select the appropriate Target.
  8. Once the target as been selected, the Swift Package Product will be added to that Target.

**Note: All the above mentioned steps are only required to be done once whenever the Application target is being linked with OT SDK Swift Package. After this is done, during next releases, the application can directly fetch the latest OT SDK Swift Package by going to File -> Packages -> Update to Latest Package Version. When updating the package version, make sure that you publish to the latest version.


Import using .xcframework

If your app has used a previous version of the SDK prior, remove those frameworks from the application target.

  1. Download and unzip the SDK from the OneTrust Admin.

  2. OTPublishersHeadlessSDK-XCFramework folder contains a pre-compiled binary package as XCFramework.

  3. Drag and drop OTPublishersHeadlessSDK.xcframework into your {Application}.xcworkspace or {Application}.xcodeproj.

  4. Check Copy Items If Needed and proceed.

  5. Verify that OTPublishersHeadlessSDK.xcframework is added to Frameworks, Libraries, and Embedded Contents under Target's General tab.

  6. Select Embed & Sign for OTPublishersHeadlessSDK.xcframework.

  7. Run the app.


Import using .framework

If your app has used a previous version of the SDK prior, remove those frameworks from the application target.

  1. Download and unzip the SDK from the OneTrust Admin.

  2. Select the SDK that is compatible with the version of Xcode you are running.

    1. Folders suffixed with -Test contain simulator and device architectures.
    2. Folders without -Test contain only device specific architectures.
  3. Drag and drop OTPublishersHeadlessSDK.framework into your {Application}.xcworkspace or {Application}.xcodeproj.

  4. Check Copy Items If Needed and proceed.

  5. Verify that OTPublishersHeadlessSDK.framework is added to Frameworks, Libraries, and Embedded Contents under Target's General tab.

    1. Select Embed & Sign for OTPublishersHeadlessSDK.xcframework.
  6. Run the app.


Accessing OT SDK in Application

Once you have added the SDK, import it to begin accessing methods.

iOS

// Swift
import OTPublishersHeadlessSDK

tvOS

// Swift
import OTPublishersHeadlessSDKtvOS

📘

tvOS

The tvOS SDK still uses iOS's OTPublishersHeadlessSDK as the class. This makes sharing and reusing code between iOS and tvOS easier. The library was bifurcated into two frameworks in order to keep the architectures and view controllers separate, otherwise the size would be too large to deploy through package managers.