iOS

Swift

TrustArc.sharedInstance
    .setDomain("mac_trustarc.com")
    .setMode(.iabTCFv2_2)
    .start(viewController: self) { shouldShowConsentUI in
        if shouldShowConsentUI {
            TrustArc.sharedInstance.openCM(in: self, delegate: self)
        }
    }

Objective-C

[[[[TrustArc sharedInstance] setDomain:@"mac_trustarc.com"]
    setMode:SdkModeIabTCFv2_2]
    startWithViewController:self
    completion:^(BOOL shouldShowConsentUI) {
        if (shouldShowConsentUI) {
            [[TrustArc sharedInstance] openCMIn:self delegate:self];
        }
    }];

As specified by the IAB, the consent collected will be encoded and stored locally in UserDefaults. You may access these values using their specific keys.

Here is an example of how applications or third-party SDKs (vendors) access the consent information stored on the device.

Swift

NotificationCenter.default.addObserver(
    forName: UserDefaults.didChangeNotification,
    object: nil,
    queue: .main
) { _ in
    let tcString = UserDefaults.standard.string(forKey: "IABTCF_TCString")
    print("IABTCF_TCString", tcString ?? "nil")
}

Objective-C

[[NSNotificationCenter defaultCenter]
    addObserverForName: NSUserDefaultsDidChangeNotification
    object: nil
    queue: [NSOperationQueue mainQueue]
    usingBlock:^(NSNotification * _Nonnull note) {
        NSString *tcString = [[NSUserDefaults standardUserDefaults]
            stringForKey:@"IABTCF_TCString"];
        NSLog(@"IABTCF_TCString %@", tcString);
    }
];

Additionally, the TCF string value can also be obtained by using TrustArc.sharedInstance.getTcfString(). For more information, refer to the API documentation section.

TrustArc  ·  Mobile App Consent — IAB TCF v2.2: iOS  ·  www.trustarc.com