This screen displays the user consent details and allows granular control, enabling users to provide consent for each individual item. User can also modify existing consent in that settings page.
Please note that we are only talking about whether the user has confirmed a choice and not whether he has accepted or refused consent.
Implement delegates related to user consent
When the user has completed the consent process and given their consent, this delegate informs you whether our CMP did finish successfully or did fail. Depending on these delegate you can trigger some action on your end depending on your business logic
Add an extension to your ViewController that conform to that Delegate
Full View Controller implementation:
INFO
In the example below, we start with the previous basic example found at Step 2: Basic Integration
Implement AppConsentDelegate in your header ile (.h)
Assign ACNotice delegate to self
Then implement the delegate methods in your implementation file (.m) as per below
Full implementation ViewController implementation
ExampleObjcViewController.h
ExampleObjcViewController.m
INFO
In the example below, we start with the previous basic example found at Step 2: Basic Integration
Conform your ViewModel to AppConsentDelegate as per below
Add 2 published properties on your ViewModel in order to react on delegates
Full View Model implementation
SwiftUI View implementation AppConsentViewModel to receive delegates events
Check for update
This method allows you to check from our servers whether your Notice has been updated since it was last displayed on your user's device.
INFO
The method will return true if you have modified the Source and/or Notice from your dashboard and, if and only if, you have configured your Notice to update for all your users.
Our latest SDK supports both traditional callback-based APIs and the modern Swift concurrency approach using async/await for most methods.
Check for update - callback-based
Check for update - Modern concurrency
Not available
GCM Status
INFO
This method shows the current status of GCMv2 (Google Consent Mode V2).
Before calling up this method, it's best to make sure that the user has already given his consent and that it's up to date, and that the CMP doesn't need to be redisplayed.
Otherwise :
either the saved value of the old consent will be returned
or the default values of your FirebaseAnalytics Info.plist configuration file will be returned
extension ExampleViewController: AppConsentDelegate {
func appConsentDidFinish() {
// Below you can place your own business logic, for example grab the general consent status
print("🔥 AppConsentUnified Delegate: did finish")
let consentStatus = appConsent.consentStatus()
print("🔥 AppConsentUnified Delegate: consent status => \(consentStatus.description)")
}
func appConsentDidFail(_ error: Error?) {
print("🔥 AppConsentUnified Delegate: did fail, \(error?.localizedDescription ?? "No error details")")
}
func appConsentDidAppear() {
print("🔥 AppConsentUnified Delegate: did appear")
}
func appConsentDidDisappear() {
print("🔥 AppConsentUnified Delegate: did disappear")
}
}
import AppConsentUnified
class ExampleViewController: UIViewController {
// Notice Object
private(set) var notice: ACNotice!
override func viewDidLoad() {
super.viewDidLoad()
self.appConsent = ACNotice(withAppKey: "YOUR_APP_KEY")
// Delegate is used to get some callbacks when CMP finishes its execution
self.appConsent.delegate = self
// Present CMP when you need it (it can after some internal logic on your end not necessarely here as the example shows)
self.notice.presentNotice(viewController: self)
}
}
fileprivate extension ExampleViewController: AppConsentDelegate {
func appConsentDidFinish() {
// Below you can place your own business logic, for example grab the general consent status
print("🔥 AppConsentUnified Delegate: did finish")
let consentStatus = notice.consentStatus()
print("🔥 AppConsentUnified Delegate: consent status => \(consentStatus.description)")
}
func appConsentDidFail(_ error: Error?) {
print("🔥 AppConsentUnified Delegate: did fail, \(error?.localizedDescription ?? "No error details")")
}
func appConsentDidAppear() {
print("🔥 AppConsentUnified Delegate: did appear")
}
func appConsentDidDisappear() {
print("🔥 AppConsentUnified Delegate: did disappear")
}
}
- (void)appConsentDidFail:(NSError * _Nullable)error {
NSLog(@"🔥 AppConsentUnified Delegate: did fail %@", error.localizedDescription);
}
- (void)appConsentDidFinish {
NSLog(@"🔥 AppConsentUnified Delegate: did finish");
// Here you can place your own business logic, for example grab the general consent status
ACConsentStatus consentStatus = [self.appConsent consentStatus];
switch (consentStatus) {
case ACConsentStatusAllowed:
NSLog(@"🔥 AppConsentUnified Delegate: consent status Allowed");
break;
case ACConsentStatusDenied:
NSLog(@"🔥 AppConsentUnified Delegate: consent status Denied");
case ACConsentStatusMixed:
NSLog(@"🔥 AppConsentUnified Delegate: consent status Mixed. Need to verify per purposes");
default:
break;
}
}
-(void)appConsentDidAppear {
NSLog(@"🔥 AppConsentUnified Delegate: did appear");
}
- (void)appConsentDidDisappear {
NSLog(@"🔥 AppConsentUnified Delegate: did disappear");
}
#import "ExampleObjcViewController.h"
@interface ExampleObjcViewController ()
@property(nonatomic, strong) ACNotice *appConsent;
@end
@implementation ExampleObjcViewController
- (void)viewDidLoad {
[super viewDidLoad];
// initialise notice
self.appConsent = [[ACNotice alloc] initWithAppKey:@"YOUR_APP_KEY"];
// Set Delegate
[self.appConsent setDelegate:self];
// Present Notice
[self.appConsent presentNoticeWithViewController:self];
}
- (void)appConsentDidFail:(NSError * _Nullable)error {
NSLog(@"🔥 AppConsentUnified Delegate: did fail %@", error.localizedDescription);
}
- (void)appConsentDidFinish {
NSLog(@"🔥 AppConsentUnified Delegate: did finish");
// Here you can place your own business logic,
// An example here: get the general consent status
ACConsentStatus consentStatus = [self.appConsent consentStatus];
switch (consentStatus) {
case ACConsentStatusAllowed:
NSLog(@"🔥 AppConsentUnified Delegate: consent status Allowed");
break;
case ACConsentStatusDenied:
NSLog(@"🔥 AppConsentUnified Delegate: consent status Denied");
case ACConsentStatusMixed:
NSLog(@"🔥 AppConsentUnified Delegate: consent status Mixed. Need to verify per purposes");
default:
break;
}
}
-(void)appConsentDidAppear {
NSLog(@"🔥 AppConsentUnified Delegate: did appear");
}
- (void)appConsentDidDisappear {
NSLog(@"🔥 AppConsentUnified Delegate: did disappear");
}
@end
final class AppConsentViewModel: ObservableObject {
private(set) var appConsent: ACNotice
@Published var noticeCompleted = false
@Published var noticeError: Error?
init(ac: ACNotice) {
self.appConsent = ac
}
func presentNotice() {
if let rootVC = UIApplication.shared.keyWindow?.rootViewController {
// Set delegate
appConsent.delegate = self
// Present Notice
appConsent.presentNotice(viewController: rootVC)
} else {
noticeError = NSError(domain: "your_bundle_id",
code: 999, // Choose your internal code if needed
userInfo: [
NSLocalizedFailureReasonErrorKey:
"Unable to present notice, keyWindow is nil"
])
}
}
}
final class AppConsentViewModel: ObservableObject {
private(set) var appConsent: ACNotice
@Published var noticeCompleted = false
@Published var noticeError: Error?
init(notice: ACNotice) {
self.appConsent = notice
}
func presentNotice() {
if let rootVC = UIApplication.shared.keyWindow?.rootViewController {
appConsent.delegate = self
appConsent.presentNotice(viewController: rootVC)
} else {
noticeError = NSError(domain: "your_bundle_id", code: 999, userInfo: [NSLocalizedFailureReasonErrorKey: "Unable to present notice, keyWindow is nil"])
}
}
}
// AppConsent Delegate
extension AppConsentViewModel: AppConsentDelegate {
func appConsentDidFinish() {
print("🔥 AppConsentUnified Delegate: did finish")
noticeCompleted = true
}
func appConsentDidFail(_ error: Error?) {
print("🔥 AppConsentUnified Delegate: did fail, \(error?.localizedDescription ?? "No error details")")
noticeError = error
}
func appConsentDidAppear() {
print("🔥 AppConsentUnified Delegate: did appear")
}
func appConsentDidDisappear() {
print("🔥 AppConsentUnified Delegate: did disappear")
}
}
import SwiftUI
import AppConsentUnified
struct ContentView: View {
@StateObject private var appConsentViewModel: AppConsentViewModel
init(appConsentViewModel: AppConsentViewModel) {
self._appConsentViewModel = StateObject(wrappedValue: appConsentViewModel)
}
var body: some View {
VStack {
// YOUR VIEW ELEMENTS
Text("My View")
}.onAppear {
let appConsent = ACNotice(withAppKey: "YOUR_APP_KEY")
// present notice
appConsentViewModel.presentNotice()
}.onReceive(appConsentViewModel.$noticeCompleted) { success in
// Here you can place your own business logic, for example grab the general consent status
let consentStatus = appConsentViewModel.appConsent.consentStatus()
print("🔥 AppConsentUnified Delegate: did finish consent status => \(consentStatus.description)")
}.onReceive(appConsentViewModel.$noticeError) { error in
// Here you can place your own business logic for error handling
}
}
}
appConsent.checkForUpdate { [weak self] needUpdate in
if needUpdate {
// Your Notice has been updated, you must represent the CMP to your users
// You can call presentNotice as per the below example
guard let self else { return }
appConsent.presentNotice(viewController: self)
}
}
__weak typeof(self) weakSelf = self;
[self.notice checkForUpdate:^(BOOL needUpdate) {
if (needUpdate) {
__strong typeof(self) strongSelf = weakSelf;
if (!strongSelf) return;
// Your Notice has been updated, you must represent the CMP to your users
// You can call presentNotice as per the below example
[self.notice presentNoticeWithViewController:strongSelf];
}
}];