Compliant with GDPR, CCPA, COPPA, LGPD, PECR, PDPA, PIPEDA, and more.
UniConsent CMP is a package for handling GDPR IAB TCF 2.3 consent management in iOS. You can find a demo app integrated with UniConsent CMP in the "UniConsentDemo" directory.
Add UniConsent.xcframework into your project. In your target's General > Frameworks, Libraries, and Embedded Content, set UniConsent.xcframework to Embed & Sign.
Before integrating the SDK, customize the consent banner appearance in the UniConsent Dashboard to match your brand and optimize consent rates.
Go to Projects → Select your Project → Settings → Step 5: UI & Style Settings to configure:
For more precise control, add custom CSS in the CSS Content field under Step 5. This is recommended to make the banner feel native to your app and achieve the best consent rate:
/* Example: Style the accept button to match your brand */
.unic-btn-accept {
background-color: #4CAF50;
border-radius: 8px;
font-weight: 600;
}
/* Example: Adjust banner font */
.unic-banner {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}
/* Example: Make the reject button less prominent */
.unic-btn-reject {
background-color: transparent;
border: 1px solid #ccc;
color: #666;
}
Tip: A well-branded consent UI that feels native to your app typically achieves higher consent rates. Users are more likely to engage positively with a banner that matches the look and feel they expect.
To use the UniConsent CMP in your app, follow these steps:
Initialize the CMP with an App ID from your account manager:
import UniConsent
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Init CMP with appId
UniConsentCMP.shared.initialize(apiId: "YOUR_APP_ID_CHANGE_THIS")
return true
}
Display the CMP UI:
// Display CMP as full-screen modal (default)
UniConsentCMP.shared.setUIStage(.GDPRFirstScreen)
UniConsentCMP.shared.launchCMP(rootVC: self)
// Display CMP as a modal bottom sheet
UniConsentCMP.shared.launchCMP(rootVC: self, displayMode: .modalSheet)
// Display CMP as a center dialog
UniConsentCMP.shared.launchCMP(rootVC: self, displayMode: .dialog)
Available display modes (CMPDisplayMode):
.fullScreen — Full-screen modal presentation (default).modalSheet — Bottom sheet with drag handle (iOS 15+).dialog — Centered dialog with dimmed backgroundListen for consent dismiss with CMPUIDelegate:
class ViewController: UIViewController, CMPUIDelegate {
func showCMP() {
UniConsentCMP.shared.view.delegate = self
UniConsentCMP.shared.setUIStage(.GDPRFirstScreen)
UniConsentCMP.shared.launchCMP(rootVC: self, displayMode: .modalSheet)
}
func onDismiss() {
// Called when the user closes the consent UI
print("TC String:", UniConsentCMP.shared.getTCString())
}
}
Automatically check if consent is expired when the vendorList updates:
// Automatic check if consent is expired when vendorList updates
if UniConsentCMP.shared.shouldRequestConsent() {
UniConsentCMP.shared.launchCMP(rootVC: self)
}
Get the tcString if required:
// Get tcString if required
UniConsentCMP.shared.getTCString()
Read the consent status:
// Check consent for a specific IAB purpose
UniConsentCMP.shared.isAllowPurposeById(purposeId: 1)
// Check consent for a specific IAB vendor
UniConsentCMP.shared.isAllowVendorById(vendorId: 1)
// Get all allowed purpose/vendor IDs
UniConsentCMP.shared.getAllowedPurposeIds()
UniConsentCMP.shared.getAllowedVendorIds()
// Check if GDPR applies
UniConsentCMP.shared.gdprApplies
// Check if any consent has been given
UniConsentCMP.shared.isConsentGiven()
Reset consent status if required:
// Reset consent status if required
UniConsentCMP.shared.clearConsentData()
// Initialize
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[[UniConsentCMP shared] initializeWithApiId:@"YOUR_APP_ID"];
return YES;
}
// Display CMP (full screen by default)
[UniConsentCMP.shared launchCMPWithRootVC:self];
// Display CMP with a specific display mode
// Use CMPDisplayModeFullScreen, CMPDisplayModeModalSheet, or CMPDisplayModeDialog
[UniConsentCMP.shared launchCMPWithRootVC:self displayMode:CMPDisplayModeModalSheet];
Setup default consent status KV:
<key>FIREBASE_ANALYTICS_COLLECTION_ENABLED</key> <false/>
<key>GOOGLE_ANALYTICS_DEFAULT_ALLOW_ANALYTICS_STORAGE</key> <false/>
<key>GOOGLE_ANALYTICS_DEFAULT_ALLOW_AD_STORAGE</key> <false/>
<key>GOOGLE_ANALYTICS_DEFAULT_ALLOW_AD_USER_DATA</key> <false/>
<key>GOOGLE_ANALYTICS_DEFAULT_ALLOW_AD_PERSONALIZATION_SIGNALS</key> <false/>
Control analytics based on the consent flags:
// SDK Version <= 25.6.1
public func onDismiss() {
if(UniConsentCMP.shared.isAllowPurposeById(purposeId: 1)) {
Analytics.setConsent([
.analyticsStorage: .granted,
.adStorage: .granted,
.adUserData: .granted,
.adPersonalization: .granted,
])
Analytics.setAnalyticsCollectionEnabled(true);
} else {
Analytics.setConsent([
.analyticsStorage: .denied,
.adStorage: .denied,
.adUserData: .denied,
.adPersonalization: .denied,
])
Analytics.setAnalyticsCollectionEnabled(false);
}
// other logics such as send analytics events
}
Find more info at Set up consent mode for apps