UID2 SDK for iOS Reference Guide
You can use the UID2 SDK for iOS to facilitate the process of establishing client identity using UID2 and retrieving advertising tokens on iOS devices.
The following iOS-related plugins, and associated documentation, are also available:
|To use the Google Mobile Ads (GMA) SDK to send UID2 tokens as secure signals in ad requests from iOS apps||UID2 GMA Plugin for iOS Integration Guide|
|To use the Google Interactive Media Ads SDK for iOS to send UID2 tokens as secure signals in ad requests from iOS apps||UID2 IMA Plugin for iOS Integration Guide|
This SDK simplifies integration with UID2 for any publishers who want to support UID2 for apps running on iOS devices. The following table shows the functions it supports.
|Encrypt Raw UID2 to UID2 Token||Decrypt UID2 Token||Generate UID2 Token from DII||Refresh UID2 Token|
|Not supported||Not supported||Not supported||Supported|
This documentation is for the UID2 iOS SDK version 0.2.0.
The UID2 iOS SDK is designed to manage UID2 identity on behalf of iOS apps. It enables UID2 identity to be persisted across app lifecycles by securely storing the identity on a device via platform-native encryption tools.
By default, the SDK automatically refreshes UID2 identity based on expiration dates. However, you can disable this to allow implementing apps to manage the UID2 identity lifecycle manually.
GitHub Open-Source Repository
This SDK is in the following open-source GitHub repository:
Minimum requirements for this SDK are as follows:
- Xcode version: 14.0+
- iOS minimum target version: 13.0+
- Swift version: 5.0+
Install the iOS SDK via Swift Package Manager (SPM). There are two installation options:
Installing with Package.swift
Add the following dependency to Package.swift:
.package(url: \"https://github.com/IABTechLab/uid2-ios-sdk.git\", from: "0.2.0"),
Installing with Xcode
Add the following dependency via Xcode:
The initial UID2 Identity must be generated by the implementing application and then passed into the UID2 SDK. Because of security requirements, the UID2 Mobile SDKs cannot create new UID2 identities.
The UID2 Mobile SDKs can perform refreshes of UID2 identities, after an Identity is established. This is because the refresh functionality relies on the refresh tokens that are part of the UID2 Identity.
The UID2Manager singleton is the primary developer API for the UID2 Android and iOS SDKs. It is responsible for storing, refreshing, and retrieving UID2 Identity.
For iOS, the
UID2Manager is initialized automatically the first time it is accessed. You can configure it to support automatic or manual refresh capabilities.
This section includes the functions and variables that are part of the UID2Manager API.
The following functions are available as part of the UID2Manager API:
Sets the UID2 Identity to be managed by the SDK.
Resets or removes the UID2 Identity currently being managed by the SDK.
Manually refreshes the UID2 Identity being managed by the SDK.
If the current UID2 Identity is valid, this function returns the UID2 token (advertising token).
Toggle for automatic refresh functionality.
The following variables are available as part of the UID2Manager API:
The Identity variable stores and returns the current UID2Identity data object being managed by the SDK.
The identityStatus variable stores and returns the status of the current UID2 Identity being managed by the SDK.
The following code samples provide examples of performing specific activities relating to managing UID2 with the UID2 iOS SDK.
Set the initial UID2 Identity:
UID2Manager.shared.setIdentity(_ identity: UID2Identity)
Get the UID2 token (advertising token) to pass to the Advertising SDK: