# Integrating the iOS SDK

This guide describes how to integrate the DT Exchange SDK into your iOS project, which uses CocoaPods for dependency management.

## Integrating with CocoaPods <a href="#h_01ezxyfqpvdb5hyxvpvpcyenz4" id="h_01ezxyfqpvdb5hyxvpvpcyenz4"></a>

CocoaPods enables you to add and manage external libraries. To integrate via CocoaPods:

1. Open a terminal and navigate to your project directory.
2. Run the following command to create a new `Podfile` if you don't already have one:

{% code title="Bash" %}

```bash
pod init
```

{% endcode %}

3. Edit the `Podfile` and add the DT Exchange pod to the desired target:

{% code title="Bash" %}

```bash
pod 'Fyber_Marketplace_SDK'
```

{% endcode %}

4. To install and update the repository, run the following command. The `pod install` command installs the SDK and its dependencies and creates a new `.xcworkspace` file for use with Xcode:

{% code title="Bash" %}

```bash
pod install --repo-update
```

{% endcode %}

5. To import the `IASDKCore` into the `AppDelegate` class, run the following command:

{% code title="Objective-C" %}

```objective-c
[IASDKCore.sharedInstance setGDPRConsentString:@"abcdef"];
```

{% endcode %}

## Downloading and Setting Up the SDK <a href="#h_01h959gwaf4djxmqnn393p4knq" id="h_01h959gwaf4djxmqnn393p4knq"></a>

To download the DT Exchange iOS SDK, click here:

{% @dt-download-buttons/DTX-Download-Button-ios %}

{% hint style="success" %}
The DT Exchange SDK zip folder includes a test app that demonstrates the integration process and adds functionality. It shows ads from DT Exchange and troubleshoots issues.
{% endhint %}

### Starting the Process <a href="#h_01j6pq220brx4v9rqv1yg0kdzn" id="h_01j6pq220brx4v9rqv1yg0kdzn"></a>

* The DT iOS SDK requires a minimum deployment target of iOS 11 and is fully compatible with iOS 17.
* If you use the CocoaPods Dependency Manager, see [Integrating with CocoaPods](#h_01ezxyfqpvdb5hyxvpvpcyenz4) and then refer to [Initializing the SDK](#h_01h959gwafm6r8zapzj5khd113).

## Step 1: Integrating the Libraries <a href="#h_01h959gwafx2axgb4wwt1nxt6w" id="h_01h959gwafx2axgb4wwt1nxt6w"></a>

1. Drag the `IASDKCore` library to your Xcode project.\
   The **Choose options for adding these files** pop-up screen appears.
2. Select the **Copy items if needed** and **Create Groups** checkboxes.
3. From **Application target**→**Build Phases,** click **Link Binary With Libraries** to verify that the app target is linked with the `IASDKCore` library.
4. If missing, drag the `IASDKCore` library to the **Link Binary With Libraries** section. This links your project with the `IASDKCore` library and adds a required path to the **Framework Search Paths**.
5. Import the `IASDK` into the `AppDelegate` class:

{% code title="Objective-C" %}

```objective-c
#import <IASDKCore/IASDKCore.h>
```

{% endcode %}

## Step 2: Initializing the SDK <a href="#h_01h959gwafm6r8zapzj5khd113" id="h_01h959gwafm6r8zapzj5khd113"></a>

SDK initialization is mandatory because the DT SDK relies on the [console](https://app.gitbook.com/o/6OUMZNPaiprOF7vUBqN2/s/LbREhkP3WlLtP6TNVZ2Q/) configuration for functionality. Without it, the SDK won't operate, and no ads will display. DT recommends performing this step during the app's initialization.

The following takes place during the initialization phase:

* Initialization of SDK.
* Remote configuration fetching, parsing, loading, and local configuration update.

1. Add the following code inside the method in the `AppDelegate` class.

{% code title="Objective-C" %}

```objective-c
application:didFinishLaunchingWithOptions:
```

{% endcode %}

2. Run the following command:

{% code title="Objective-C" %}

```objective-c
[IASDKCore.sharedInstance initWithAppID:@"YOUR APP ID"
                        completionBlock:^(BOOL success, NSError * _Nullable error) {}
                        completionQueue:nil];
```

{% endcode %}

{% hint style="success" %}
All Publisher (client-side) Ad Requests are on hold until the configuration is loaded to memory. The requests resume asynchronously once the config is ready. If a timeout occurs, the Publisher receives an `ad failed` event.
{% endhint %}

{% hint style="success" %}
For further information about advanced SDK init integration, see [SDK Initialization for DT Exchange SDK](https://docs.digitalturbine.com/dt-exchange/publishers/sdk-configuration/integrating-the-ios-sdk/sdk-initialization-for-dt-exchange-sdk).
{% endhint %}

## Step 3: Configuring Apple Requirements <a href="#h_01h959gwafmpkhzway054zxn28" id="h_01h959gwafmpkhzway054zxn28"></a>

Adhering to Apple's requirements ensures that your app complies with its privacy guidelines, as described in [ATS Configuration for DT Exchange SDK](https://docs.digitalturbine.com/dt-exchange/publishers/sdk-configuration/integrating-the-ios-sdk/ats-configuration-for-dt-exchange-sdk).

### Configuring Tracking Permission Alerts with ATT Framework <a href="#step-4-optionally-configure-tracking-permission-alert-using-att-framework-for-ios-14" id="step-4-optionally-configure-tracking-permission-alert-using-att-framework-for-ios-14"></a>

App Tracking Transparency (ATT) allows you to request user consent for tracking. You must use the ATT framework and provide your users with an authorization request within your app only if you want to receive consent and access a non-zero IDFA from the device. For more information, see [App Tracking Transparency](https://developer.apple.com/documentation/apptrackingtransparency).

{% hint style="info" %}
Calling `requestTrackingAuthorization(completionHandler:)` prompts the end user for app-tracking authorization. If the user disables tracking, the IDFA is set to zero.
{% endhint %}

#### SKAdNetwork Attribution Solution <a href="#skadnetwork-attribution-solution" id="skadnetwork-attribution-solution"></a>

The [SKAdNetwork API](https://developer.apple.com/documentation/storekit/skadnetwork) enables advertisers to measure app installs in a privacy-aware manner. Configuring SKAdNetwork IDs is crucial to monetizing with DT Exchange since it allows DSPs to credit your app with installs. DT recommends that you include SKAdNetwork IDs in the `info.plist` file to maximize revenue potential.

### Getting the SKAdNetwork IDs <a href="#id-01hry22k18ewb6ypwm7f5hhhnn" id="id-01hry22k18ewb6ypwm7f5hhhnn"></a>

The SKAdNetwork IDs for DT and DT buyers are available in two regularly updated formats. Select one of the following links to retrieve the latest SKAdNetwork IDs:

* SKAdNetwork IDs in [JSON format](https://github.com/fyber-engineering/SKAdNetworks/blob/master/docs/index.json).
* SKAdNetwork IDs in [XML format](https://github.com/fyber-engineering/SKAdNetworks/blob/master/docs/skadnetwork.xml).

### Configuring the SKAdNetwork IDs <a href="#id-01hry2ffm7789xepyy78tr8pn0" id="id-01hry2ffm7789xepyy78tr8pn0"></a>

The SKAdNetwork helps track app installs in a privacy-friendly way. To configure your app with SKAdNetwork IDs:

1. Select `Info.plist` from the **Project** navigator in Xcode.
2. In the property list editor, click **Add** (+) beside a key and press **Return**.
3. In the field, type the key name: [`SKAdNetworkItems`](https://developer.apple.com/documentation/bundleresources/information_property_list/skadnetworkitems).
4. From the pop-up menu in the **Type** column, select **Array**.
5. Create an array that contains one dictionary for each of DT's recommended SKAdNetwork IDs with the single-key: [`SKAd Network Identifier`](https://developer.apple.com/documentation/bundleresources/information_property_list/skadnetworkitems/skadnetworkidentifier). The string value for the key is the ad network identifier.

### SKAdNetwork ID Manager <a href="#h_01h959gwagcg5vdny4rdd1c74h" id="h_01h959gwagcg5vdny4rdd1c74h"></a>

The [SKAdNetwork IDs Manager](https://app.gitbook.com/s/4IftQ9WUOy9feTA5sZeE/fairbid-sdk/sdk-reference/skadnetwork-id-auto-updater) tool identifies and manages SKAdNetwork IDs. This tool processes and deduplicates SKAdNetwork IDs for all buyers on DT Exchange and then generates a finalized `Info.plist;`output for streamlining integration into your app. The tool enables you to add other SKAdNetwork IDs to your final `Info.plist` file.

{% hint style="success" %}
DT recommends that you use lowercase text for the ad network identifier string.
{% endhint %}

To configure SKAdNetwork IDs, see [Configuring a Source App](https://developer.apple.com/documentation/storekit/skadnetwork/configuring_a_source_app).

## Step 4: Adding Delegates <a href="#h_01h959gwag34mr00anjymw58a1" id="h_01h959gwag34mr00anjymw58a1"></a>

Delegates manage various events and interactions related to ads. Depending on your integration, you may need to add the following delegates to your iOS integration:

* Global Ad Delegate Protocol
* Unit Delegate
* Video Content Delegate
* HTML / MRAID Delegate

For further information, see [Delegate Protocols](https://docs.digitalturbine.com/dt-exchange/publishers/sdk-configuration/integrating-the-ios-sdk/delegate-protocols).

## Step 5: Adding User Consent <a href="#h_01h959gwage1xq9vgmme2pfpdr" id="h_01h959gwage1xq9vgmme2pfpdr"></a>

User consent mechanisms comply with various data protection laws. The following regulations mandate that users' data be handled with explicit consent:

* [GDPR](#h_01j64gft6cdgx97eyg11t7dfyf)
* [CCPA](#h_01h959gwagcd68btfgwz2jk435)
* [LGPD](#h_01h959gwag1eznq5crhrytafnw)
* [COPPA](#h_01h959gwah3pc301ncg03zsfqf)
* [GPP](#gpp)

### GDPR <a href="#h_01j64gft6cdgx97eyg11t7dfyf" id="h_01j64gft6cdgx97eyg11t7dfyf"></a>

The General Data Protection Regulation ([GDPR](https://gdpr.eu/)) of the European Union requires you to implement a user consent mechanism. A user could be within the GDPR scope for your app when one or all of the following apply:

* The user is currently located in the EU.
* The user has registered with the app as an EU resident.
* The app is specifically targeted to EU users.

To comply with EU regulations and ensure seamless ad monetization, DT recommends consulting a legal advisor to determine the best approach for your business and using a Consent Management Platform (CMP).

If you haven’t updated to SDK 8.3.1 or later, you need to manually configure consent values with your CMP. The SDK automatically retrieves these values from 8.3.1 and later, eliminating the need for manual setup. For a complete list of CMPs, see the [Interactive Advertising Bureau - CMP List](https://iabeurope.eu/cmp-list/).

To incorporate GDPR consent values, run the `GDPRConsent` API in Boolean format, for example:

{% code title="Objective-C" %}

```objective-c
[IASDKCore.sharedInstance setGDPRConsent:YES]
```

{% endcode %}

Valid values:

* `True`: The user grants consent.
* `False`: The user does not grant consent.

#### **Setting Consent String**

{% hint style="warning" %}
The user's consent status must be passed to the SDK before the SDK is initialized.\
When you set a GDPR consent value for a user, DT assumes that the user is subject to GDPR rules, even if the user is outside Europe. If a user updates their consent later, you only need to call the API again with the new value.
{% endhint %}

To set the GDPR consent string, use the following API:

{% code title="Objective-C" %}

```objective-c
[IASDKCore.sharedInstance setGDPRConsentString:@"abcdef"];
```

{% endcode %}

### CCPA <a href="#h_01h959gwagcd68btfgwz2jk435" id="h_01h959gwagcd68btfgwz2jk435"></a>

The California Consumer Privacy Act of 2018 ([CCPA](https://iabtechlab.com/standards/ccpa/)) protects the personal information of California residents and applies to all companies operating in California. If a California resident uses a mobile app developer's app, CCPA applies to the developer and every company that processes the personal information of the app's users.\
For more information on CCPA, see [IAB CCPA Compliance Framework](https://www.iab.com/guidelines/ccpa-framework/).

To set the CCPA consent string, use the following API:

{% code title="Objective-C" %}

```objective-c
IASDKCore.sharedInstance.CCPAString = @"1YNN";
```

{% endcode %}

DT supports the following values for the US Privacy String:

* `1---`: CCPA does not apply, for example, the user is not a California resident.
* `1YNN`: User does NOT opt out, ad experience continues.
* `1YYN`: User opts out of targeted advertising.

For more information, see [US Privacy IAB documentation](https://github.com/InteractiveAdvertisingBureau/USPrivacy/blob/master/CCPA/US%20Privacy%20String.md).

To clear the CCPA-provided data, pass a `nil` value and use the following Clear Privacy Setting:

{% code title="Objective-C" %}

```objective-c
IASDKCore.sharedInstance.CCPAString = nil;
```

{% endcode %}

{% hint style="success" %}
The DT Exchange SDK does not validate the provided CCPA string and passes it as-is.
{% endhint %}

### LGPD <a href="#h_01h959gwag1eznq5crhrytafnw" id="h_01h959gwag1eznq5crhrytafnw"></a>

The Brazilian General Data Protection Law, the Lei Geral de Proteção de Dados Pessoais ([LGPD](https://lgpd-brazil.info/)), mandates processing personal data for legitimate, specific, explicit, and communicated purposes.

To set the LGPD consent value, use the following API:

{% tabs %}
{% tab title="Swift" %}

```swift
IASDKCore.sharedInstance().lgpdConsent = .given
IASDKCore.sharedInstance().lgpdConsent = .denied
```

{% endtab %}

{% tab title="Objective-C" %}

```objective-c
[[IASDKCore sharedInstance] setLGPDConsent:IALGPDConsentTypeGiven];
[[IASDKCore sharedInstance] setLGPDConsent:IALGPDConsentTypeDenied];
```

{% endtab %}
{% endtabs %}

Valid values:

* `IALGPDConsentTypeGiven`: User grants consent.
* `IALGPDConsentTypeDenied`: User does not grant consent.

If the consent value is not set, the default is `no consent`.

### COPPA <a href="#h_01h959gwah3pc301ncg03zsfqf" id="h_01h959gwah3pc301ncg03zsfqf"></a>

The Children's Online Privacy Protection Act of 1998 ([COPPA](https://www.ftc.gov/legal-library/browse/rules/childrens-online-privacy-protection-rule-coppa)) is a federal law that imposes specific requirements on websites and online service operators to protect the privacy of children under 13.

#### COPPA API for Flagging Specific Users <a href="#h_01h959gwah2bbwk5ampns6hq97" id="h_01h959gwah2bbwk5ampns6hq97"></a>

iOS SDK 8.2.1+ supports the COPPA API, which allows publishers to flag specific end users as children as required under COPPA. It is the Publisher's responsibility to decide whether to use the COPPA API or to treat all users as children. For instructions on flagging all users as children, see [COPPA](https://docs.digitalturbine.com/dt-exchange/publishers/getting-started-with-dt-exchange/privacy/coppa).

iOS SDK 8.2.1+ supports the COPPA API, which allows publishers to flag specific end users as children as required under COPPA. It is the publisher’s responsibility to decide whether to use the COPPA API or to treat all users as children. For COPPA configuration options, see [COPPA](https://docs.digitalturbine.com/dt-exchange/publishers/getting-started-with-dt-exchange/privacy/coppa).

**Important**

{% hint style="warning" %}

* Execute the COPPA API after successfully initializing the DT SDK.
* Pass the COPPA state after every successful init of the SDK.
  {% endhint %}

To confirm that the target audience of the application applies to COPPA, use the following API:

{% tabs %}
{% tab title="Swift" %}

```swift
IASDKCore.sharedInstance().coppaApplies = .given
```

{% endtab %}

{% tab title="Objective-C" %}

```objective-c
[IASDKCore.sharedInstance.coppaApplies = IACoppaAppliesTypeGiven;
```

{% endtab %}
{% endtabs %}

### GPP

The IAB Global Privacy Protocol ([GPP](https://globalprivacyplatform.com/)) is a standardized framework for managing and transmitting user consent and privacy signals across the digital advertising ecosystem.

GPP is supported starting with iOS SDK 8.4.6. For more information, see [gpp](https://docs.digitalturbine.com/dt-exchange/publishers/getting-started-with-dt-exchange/privacy/gpp "mention").

## Step 6: (Optional) Setting User IDs <a href="#h_01h959gwahdy2fnpk60ktzvd80" id="h_01h959gwahdy2fnpk60ktzvd80"></a>

This section describes how to set a User ID that is cached on the device and does not need to be passed in every session.

### Setting a User ID <a href="#h_01j6pv3nh4h4427d01gm17bmhm" id="h_01j6pv3nh4h4427d01gm17bmhm"></a>

The User ID is sent as is, without validation or modification.\
To reset the User ID on a device, pass a `nil` or an empty string in the following format.

{% code title="Objective-C" %}

```objective-c
@property (atomic, nullable) NSString *userID*
// Example:
IASDKCore.sharedInstance.userID = @"User_123456"
```

{% endcode %}

### Setting Introspection (reflection) Integration <a href="#h_01j6pv5hky08sy1j7bgzx274tx" id="h_01j6pv5hky08sy1j7bgzx274tx"></a>

To run an integration using introspection (reflection), run the following script:

{% code title="Objective-C" %}

```objective-c
Class IASDKCore        = NSClassFromString(@"IASDKCore");
SEL sharedInstanceSel  = NSSelectorFromString(@"sharedInstance");
SEL setUserID          = NSSelectorFromString(@"setUserID:");
id sharedInstance      = [IASDKCore performSelector:sharedInstanceSel];
[sharedInstance performSelector:setUserID withObject:@"User_123456"];
```

{% endcode %}

<br>
