IAB Transparency and Consent Framework consent string decoder in Objective-C (and by extension in Swift) compliant with both IAB TCF mobile v1.1 & v2.0, for any IABConsentString
Swift Package Manager
Add the following to your Package.swift
dependencies:
.package(url: "https://github.com/Singlespot/IAB-TCF-V2.git", from: "master"),
And then import wherever needed: import IAB_TCF_V2
The following API methods give everything needed to interpret the consent from the localy stored TCString.
#import "SPTIabTCFApi.h"
...
SPTIabTCFApi *iabAPI = [SPTIabTCFApi new];
[iabAPI isVendorConsentGivenFor:<VendorId>];
[iabAPI isVendorLegitimateInterestGivenFor:<VendorId>];
[iabAPI isPurposeConsentGivenFor:<PurposeId>];
[iabAPI isPurposeLegitimateInterestGivenFor:<PurposeId>];
[iabAPI isPublisherPurposeConsentGivenFor:<PurposeId>];
[iabAPI isPublisherPurposeLegitimateInterestGivenFor:<PurposeId>];
[iabAPI isPublisherCustomPurposeConsentGivenFor:<PurposeId>];
[iabAPI isPublisherCustomPurposeLegitimateInterestGivenFor:<PurposeId>];
[iabAPI isSpecialFeatureOptedInFor:<FeatureId>];
import IAB_TCF_V2_API
...
let iabAPI = SPTIabTCFApi().decodeTCString(string)
iabAPI.isVendorConsentGivenFor(vendorId: <VendorId>)
iabAPI.isVendorLegitimateInterestGivenFor(vendorId: <VendorId>)
iabAPI.isPurposeConsentGivenFor(purposeId: <PurposeId>)
iabAPI.isPurposeLegitimateInterestGivenFor(purposeId: <PurposeId>)
iabAPI.isPublisherPurposeConsentGivenFor(purposeId: <PurposeId>)
iabAPI.isPublisherPurposeLegitimateInterestGivenFor(purposeId: <PurposeId>)
iabAPI.isPublisherCustomPurposeConsentGivenFor(purposeId: <PurposeId>)
iabAPI.isPublisherCustomPurposeLegitimateInterestGivenFor(purposeId: <PurposeId>)
iabAPI.isSpecialFeatureOptedInFor(specialFeatureId: <FeatureId>)
Notes :
- Methods
isVendorConsentGivenFor
andisPurposeConsentGivenFor
are looking for v2 AND v1 TC strings and interpreting consents from both prioritizing v2 (if the two are present). If v1 need to be ignored an argumentignoreV1
can be set as follow (from previous code exemple):iabAPI.ignoreV1 = YES
. - All consents are directly read from the consent string (rather than from IAB storing keys - c.f. here - for more consistancy). Indeed from the experience of v1 mobile, not all CMP used to set all the keys, and the decoder is fast enought 😉.
To officially comply with IAB Transparency and Consent Framework (TCF) mobile, decoded parts of the TC string must be stored localy in [NSUserDefaults standartUserDefault]
under precise keys defined here for v1 and there for v2
Fortunatly our API does it all for you simply by setting the new TCString :
[[SPTIabTCFApi new] setConsentString: <newTCString>];
SPTIabTCFApi().consentString = <newTCString>
IAB TCF version is automatically detected and everything is stored at the right place. You can then read the new stored consent using code from paragraph above.
SPTIabTCFApi
also allows to manually set each and every value of decoded parts of the consent string if needed.
Sometime reading consents from a TCString is needed without necessarily storing the string itself. Use the following code to obtain a model with all the property of IAB Transparency and Consent Framework v1.1 or v2
SPTIabTCFModel *model = [SPTIabTCFApi decodeTCString:<aTCString>];
let model = SPTIabTCFApi.decodeTCString(<aTCString>)
This model has the same methods as defined in 1. Reading consent from a localy stored TCString to interpret consents.
- A coder if needed (or if someone wants to do it 😊)