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.
-
Add Podfile to your Application if using CocoaPod for the first time. Please refer to Cocoapods Documentation for additional guidance.
-
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'
-
Open Terminal, change the working directory to the directory where Podfile resides, and Run
pod install
. -
Open
{Application}.xcworkspace
file in Xcode -
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.
- Open the Application project or workspace.
- Next, select
File -> Add Packages...
. This will pop up the Swift Packages screen. - 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.
Platform | SPM Package URL |
---|---|
iOS | https://github.com/Zentrust/OTPublishersHeadlessSDK |
tvOS | https://github.com/Zentrust/OTPublishersHeadlessSDKtvOS |
- 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 theProject
. - Choose the
Dependency Rule
that is appropriate for your project and selectExact Version
and specify the version of the SDK you'd like to import. - Choose the
Project
by selecting the Project to which your application target belongs to. - Now on the bottom-right of the pop-up, you will see that the
Add Package
button is now enabled. - Click on the button. This will now start resolving the Swift package for you.
- 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. - Select the appropriate Target.
- 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
.xcframework
If your app has used a previous version of the SDK prior, remove those frameworks from the application target.
-
Download and unzip the SDK from the OneTrust Admin.
-
OTPublishersHeadlessSDK-XCFramework
folder contains a pre-compiled binary package as XCFramework. -
Drag and drop
OTPublishersHeadlessSDK.xcframework
into your{Application}.xcworkspace
or{Application}.xcodeproj
. -
Check Copy Items If Needed and proceed.
-
Verify that
OTPublishersHeadlessSDK.xcframework
is added to Frameworks, Libraries, and Embedded Contents under Target's General tab. -
Select Embed & Sign for
OTPublishersHeadlessSDK.xcframework
. -
Run the app.
Import using .framework
.framework
If your app has used a previous version of the SDK prior, remove those frameworks from the application target.
-
Download and unzip the SDK from the OneTrust Admin.
-
Select the SDK that is compatible with the version of Xcode you are running.
- Folders suffixed with
-Test
contain simulator and device architectures. - Folders without
-Test
contain only device specific architectures.
- Folders suffixed with
-
Drag and drop
OTPublishersHeadlessSDK.framework
into your{Application}.xcworkspace
or{Application}.xcodeproj
. -
Check Copy Items If Needed and proceed.
-
Verify that
OTPublishersHeadlessSDK.framework
is added to Frameworks, Libraries, and Embedded Contents under Target's General tab.- Select Embed & Sign for
OTPublishersHeadlessSDK.xcframework
.
- Select Embed & Sign for
-
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.
Updated about 1 year ago