Setup
Follow these steps to setup the Didomi iOS and tvOS SDK:
Requirements
We offer our SDK as a pre-compiled binary package as a XCFramework that you can add to your application. We support iOS versions >= 9 and tvOS versions >= 11.
Add the SDK to your project
The package can be added using CocoaPods or manually.
Using CocoaPods
The package can be added using CocoaPods:
1. If you haven't already, install the latest version of CocoaPods.
2. Add this line to your Podfile
:
Using Swift Package Manager
The iOS SDK is available through Swift Package Manager as a binary library. In order to integrate it into your iOS or tvOS project follow the instructions below:
Open your Xcode project
Select your project in the navigator area
Select your project in the PROJECT section
Select the Package Dependencies
Click on the + button
Copy the package url https://github.com/didomi/didomi-ios-sdk-spm into the search bar
Select the didomi-ios-sdk-spm package from the list
Click on Add Package
From the Choose Package Products for the didomi-ios-sdk-spm screen click on Add Package
Your setup should end up looking like this:
Manually
The package can also be added manually as explained below:
Download and unzip the latest version of our framework for Xcode >= 12: https://sdk.didomi.io/ios/didomi-ios-sdk-2.14.0-xcframework.zip
In Xcode, select your project.
In Xcode, select your project.
Then, select your app target.
Click on the
General
tab.Scroll down to the
Embedded binaries
section.From finder, drag the
Didomi.framework
file into theEmbedded binaries
section.Make sure the
Copy items if needed
box is checked and click onfinish
Your configuration should end up looking as follows:
Objective-C projects only
The iOS Didomi SDK is written in Swift so if your app is written in Objective-C, please make sure that the Always Embed Swift Standard Libraries
flag is set to YES
as shown in the image below:
Initialize the SDK
Once our SDK has been added to your project, you need to initialize it. The initialization process will prepare the SDK for interactions with the user and your application. It is important to launch the SDK initialization as soon as possible.
In the AppDelegate
, make sure to import the Didomi
module, then call the initialize
method and pass your API key:
Keep in mind that the SDK initialization is an asynchronous process so you must avoid interacting with the Didomi
object until it is actually ready to handle your requests. Use the onReady
closure in Swift or the onReadyWithCallback
method in Objective-C to register a listener for the ready event.
Setup the SDK UI
Note: the setupUI
method should be called only from your main/entry UIViewController
which in most cases should be once per app launch.
You do not need to call onReady
, isReady
or shouldConsentBeCollected
before calling setupUI
because they are called internally. Therefore, by calling this method the consent notice and preference views will only be displayed if it is required and only once the SDK is ready.
In order for the SDK to be able to display UI elements and interact with the user, you must provide a reference to your main UIViewController
. Make sure to import the Didomi
module and call the setupUI
method in Swift, setupUIWithContainerController
in Objective-C, of the SDK in the viewDidLoad
method of your main UIViewController
:
Deep links
If you are using deep links or have multiple main activities in your app make sure that the setupUI
function is called on every activity that the user can launch the app on.
This will ensure that consent is always collected as needed and there is no path where the user can launch the app without consent being collected. If setupUI
is missing at some entry points, you will see lower consent rates as users will be using the app without giving consent.
Configure the SDK
We support three options for configuring the UI and the behavior of the SDK:
Didomi Console: the SDK is configured remotely from the Didomi Console
Local file: the SDK is configured from a
didomi_config.json
file embedded in your app packageRemote file: the SDK is configured from a remote didomi_config.json file
From the Console (Recommended)
You can configure the consent notice in your app by creating a notice in your Didomi Console. It will automatically be linked to your app through your API Key and, optionally, your app package name. You can access the Didomi console here.
In order to enable this option, make sure to pass the disableDidomiRemoteConfig
parameter as false
when calling the initialize method as shown below.
The SDK will automatically use the remote configuration hosted by Didomi and cache it locally. The cached version is refreshed every 60 minutes.
Local file (deprecated)
Using your own remote file automatically disables the TCF integration. If your app uses the TCF, you must use a configuration from the Didomi Console.
Using a local file will prevent you to support multiple regulations.
With this option, you create your own SDK configuration file and embed in your app package.
The SDK behavior is configured in a didomi_config.json
file that must be placed somewhere under your project folder (see the image below for reference). Create a file with the following content to get started:
You also need to disable loading the remote configuration to ensure that only the local file is loaded and that no HTTP request is sent. Update your initialize
call to set the disableDidomiRemoteConfig
parameter to true
:
Your SDK is now setup. Read the Getting started section to learn more about how to configure it to match your app UI and requirements.
Remote file
Using your own remote file automatically disables the TCF integration. If your app uses the TCF, you must use a configuration from the Didomi Console.
Enabling this option will prevent the configuration from being loaded from the Didomi Console.
You can provide a remote URL for the SDK to download the didomi_config.json
configuration file from. That allows you to update the SDK configuration without having to re-publish you mobile application.
When that configuration is enabled, the SDK will automatically use the remote configuration and cache it locally. The cached version is refreshed every 60 minutes. If there is no connection available to download the remote file and no locally cached version, the SDK will try to use the local didomi_config.json
(provided in the app bundle) as a fallback.
To enable that option, change your call to initialize to provide the remote file URL:
Also see the reference documentation of the initialize function for more information.
Download Global Vendor List (GVL)
Since version 1.40.1 the GVL will be downloaded by default from our API before the SDK is initialized. If you want to stop this behaviour, provide the app.vendors.iab.requireUpdatedGVL
flat set to false in the CUSTOM JSON section when editing your notice on the Console app (or in your local didomi_config.json
file if that's the case).
A timeout can also be provided to specify a maximum timeout for the Download of the GVL. This can be done by providing the app.vendors.iab.updateGVLTimeout
property (in seconds).
SwiftUI
When you create a new Apple app, among other things you need to choose if your app is going to use UIKit or SwiftUI. SwiftUI is Apple's new framework for creating user interfaces in a declarative way. In order to use the Didomi SDK in a SwiftUI app we suggest the following steps.
Prepare UIViewController to call setupUI method
Create a new Swift file. You can name it for example
DidomiWrapper
.Inside this new file, create a new class that extends
UIViewController
. We need this to make sure we call thesetupUI
method when theviewDidlLoad
method is called.Inside the same file, create a struct that implements the
UIViewControllerRepresentable
protocol as shown below:
Prepare AppDelegate to call initialize method
When using SwiftUI, you might still want to use the UIApplicationDelegate
functionality. Since we want to initialize the Didomi SDK as early as possible we recommend creating a class that implements the UIApplicationDelegate
.
Create a new Swift file. You can name it for example
YourSwiftUIApp
.Create a new class that extends the
UIApplicationDelegate
protocol. Inside theapplicationDidFinishLaunchingWithOptions
method, call the Didomiinitialize
method.Create a new struct that implements the SwiftUI's
App
protocol. Use theUIApplicationDelegateAdaptor
property wrapper to connect this new struct with theAppDelegate
class. Make sure this new struct uses themain
annotation. Now you are ready to use the newDidomiWrapper
struct that you created in the previous steps.
The snippet below shows the steps explained in the points above.
Last updated