Setup - iOS

Follow these steps to setup the Didomi iOS SDK:

Add the SDK to your project

We offer our SDK as a pre-compiled package that you can add to your application. We support iOS versions >= 9.

The package can be added manually or using CocoaPods.

CocoaPods (Xcode 10.1)
CocoaPods (Xcode 10.2)
CocoaPods (Xcode 10.3)
Manually

1. If you haven't already, install the latest version of CocoaPods. 2. Add this line to your Podfile:

Podfile
pod 'Didomi', '1.11.3'

3. Run pod install in your terminal to install the Didomi SDK.

1. If you haven't already, install the latest version of CocoaPods. 2. Add this line to your Podfile:

Podfile
pod 'Didomi-xcode10.2', '1.11.3'

3. Run pod install in your terminal to install the Didomi SDK.

1. If you haven't already, install the latest version of CocoaPods. 2. Add this line to your Podfile:

Podfile
pod 'Didomi-xcode10.3', '1.11.3'

3. Run pod install in your terminal to install the Didomi SDK.

  1. In Xcode, select your project.

  2. Then, select your app target.

  3. Click on the General tab.

  4. Scroll down to the Embedded binaries section.

  5. From finder, drag the Didomi.framework file into the Embedded binaries section.

  6. Make sure the Copy items if needed box is checked and click on finish

  7. 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:

Swift 4.1
Swift 4.2
Objective-C
AppDelegate.swift
import UIKit
import Didomi
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
Didomi.shared.initialize(
apiKey: "<Your API key>",
localConfigurationPath: nil,
remoteConfigurationURL: nil,
providerId: nil,
disableDidomiRemoteConfig: false
)
// Important: views should not wait for onReady to be called.
// You might want to execute code here that needs the Didomi SDK
// to be initialized such us: analytics and other non-IAB vendors.
Didomi.shared.onReady {
// The Didomi SDK is ready to go, you can call other functions on the SDK
}
return true
}
}
AppDelegate.swift
import UIKit
import Didomi
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
Didomi.shared.initialize(
apiKey: "<Your API key>",
localConfigurationPath: nil,
remoteConfigurationURL: nil,
providerId: nil,
disableDidomiRemoteConfig: false
)
// Important: views should not wait for onReady to be called.
// You might want to execute code here that needs the Didomi SDK
// to be initialized such us: analytics and other non-IAB vendors.
Didomi.shared.onReady {
// The Didomi SDK is ready to go, you can call other functions on the SDK
}
return true
}
}
AppDelegate.h
#import <UIKit/UIKit.h>
#import <Didomi/Didomi.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@end
AppDelegate.m
#import "AppDelegate.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
Didomi *didomi = [Didomi shared];
[didomi initializeWithApiKey:@"<Your API key>" localConfigurationPath:nil remoteConfigurationURL:nil providerId:nil disableDidomiRemoteConfig:NO];
// Important: views should not wait for onReady to be called.
// You might want to execute code here that needs the Didomi SDK
// to be initialized such us: analytics and other non-IAB vendors.
[didomi onReadyWithCallback:^{
// The Didomi SDK is ready to go, you can call other functions on the SDK
}];
return YES;
}
@end

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: this method should be called once per app launch and only from your main/entryUIViewController.

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:

Swift
Objective-C
ViewController.swift
import UIKit
import Didomi
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
Didomi.shared.setupUI(containerController: self)
}
}
ViewController.h
#import <UIKit/UIKit.h>
#import <Didomi/Didomi.h>
@interface ViewController : UIViewController
@end
ViewController.m
#import "ViewController.h"
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
Didomi *didomi = [Didomi shared];
[didomi setupUIWithContainerController:self];
}
@end

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 package

  • Remote file: the SDK is configured from a remote didomi_config.json file

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.

The SDK will automatically use the remote configuration hosted by Didomi and cache it locally. The cached version is refreshed every 60 minutes. If there is no connection available to download the remote configuration and no locally cached version, the SDK will try to use a local didomi_config.json configuration file as a fallback. See the Local option below for more information on how to configure the SDK through a local configuration file.that parameter to false

Local file

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:

didomi_config.json
{
"app": {
"name": "My App Name",
"privacyPolicyURL": "http://www.website.com/privacy",
"vendors": {
"iab": {
"all": true
}
},
"gdprAppliesGlobally": true,
"gdprAppliesWhenUnknown": 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

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:

Swift
Objective-C
AppDelegate.swift
Didomi.shared.initialize(
apiKey: "<Your API key>",
localConfigurationPath: nil,
remoteConfigurationURL: "http://www.website.com/didomi_config.json",
providerId: nil,
disableDidomiRemoteConfig: false,
)
AppDelegate.m
[didomi initializeWithApiKey:@"<Your API key>" localConfigurationPath:nil remoteConfigurationURL:@"http://www.website.com/didomi_config.json" providerId:nil disableDidomiRemoteConfig:NO];

Also see the reference documentation of the initialize function for more information.