UniConsent CMP is a package for handling GDPR IAB TCF 2.2 consent management in IOS. You can find a demo app integrated with UniConsent CMP in the "uniconsent_demo" directory.
Add UniConsent.framework into your project, make sure it is Embed & Sign
.
To use the UniConsent CMP in your app, follow these steps:
Initialize the CMP with an App ID from your account manager:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Init CMP with appId
UniConsent.shared.initialize(apiId: "YOUR_APP_ID_CHANGE_THIS")
return true
}
Display the CMP UI:
// Display CMP UI
UniConsent.shared.setUIStage(.GDPRFirstScreen)
UniConsent.shared.launchCMP(rootVC: self)
Automatically check if consent is expired when the vendorList updates:
// Automatic check if consent is expired when vendorList updates
UniConsent.shared.shouldRequestConsent()
Get the tcString if required:
// Get tcString if requried
UniConsent.shared.getTCString()
Read the consent status:
// Read consent status
UniConsent.shared.isAllowPurposeById(purposeId: 1)
Reset consent status if required:
// Reset consent status if required:
UniConsent.shared.clearConsentData();
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:
public func onDismiss() {
if(UniConsent.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);
}
}
Find more info at Set up consent mode for apps