Skip to main content

iOS

The iOS AppConsent is made of two libraries:

  • the core called AppConsentKit, will always be used
  • the UI is available in two different styles, import the UI library corresponding to your choice:
    • classic the library is AppConsentUIKit
    • clear the library to import is AppConsentUIKitV3

Add AppConsent to your xCode project​

There are three ways to add AppConsent SDK to your iOS Project.

Swift Package Manager​

This is the recommended way to add our library, see the official Swift Packages documentation on Apple Developer for information about Swift Packages and how to use them in xCode.

AppConsentKit https://gitlab.datalf.chat/customers/appconsentkit-spm

AppConsentUIKitV3 https://gitlab.datalf.chat/customers/appconsentuikitv3-spm

SwiftProtobuf https://github.com/apple/swift-protobuf

You have to add all three packages to your project, including the dependency to SwiftProtobuf, because Swift Package Manager currently doesn't support dependencies on binary libraries.

Drag & Drop XCFramework​

Download AppConsent XCFramework.

AppConsentKit ​https://gitlab.datalf.chat/customers/appconsentkit-xcframework

AppConsentUIKitV3 ​https://gitlab.datalf.chat/customers/appconsentuikitv3-xcframework

In General tab of your application target, drag and drop the AppConsentKit.xcframework and the AppConsentUIKit.xcframework in Frameworks, Libraires and Embedded Content. Make sure the XCFrameworks are Embed & Sign.

note

Compatibility xCode 12 and above. Deployment target iOS 11 minimum.

You need to install SwiftProtobuf with Swift Package Manager. Current version is 1.18.0. The url of repo is https://github.com/apple/swift-protobuf

Cocoapods​

Add the following pods to your podfile:

pod 'AppConsentKit'
pod 'AppConsentUIKitV3'

Run pod install in your project directory.

note

Requires pod version >= 1.10.0.


How to use AppConsent​

  1. First get your AppKey from our AppConsent account
  2. You have to import the SDK in your code: import AppConsentUIKitV3
  3. After that, you can create and initialize ACUIKitV3 like this:
let appconsent = ACUIKitV3(withAppKey: "YOUR_APP_KEY", forceApplyGDPR: true, forceATT: true)
Important

AppConsent SDK supports the new App Tracking Transparency framework (> iOS 14+ available).You must register the NSUserTrackingUsageDescription key in your Info.plist of your application otherwise your app will crash..

App Tracking Transparency​

Apple release iOS 14.5 few days ago (26 April 2021).

One of the big changes is the new system popup called App Tracking Transparency (ATT). App Tracking Transparency requires apps to get the user’s permission before tracking their data across apps or websites owned by other companies for advertising, or sharing their data with data brokers. Apps can prompt users for permission, and in Settings, users will be able to see which apps have requested permission to track so they can make changes to their choice at any time.

Our latest frameworks (since AppConsentKit version >=1.2.11) are fully compatible and integrated with our Content Management Platform. On the App Consent back-office you must activate the use iOS Att switch, and activate the disable success screen switch (for devices below iOS 14).

Important

Don't forget to register the NSUserTrackingUsageDescription key in your Info.plist of your application otherwise your app will crash.

If you did not update your application with the letest Framework and if your application works on iOS 14.5 device, the IDFA will be 00000-00000-00000-00000.

Floating Purpose - ATT​

On the App Consent back-office, you must create an Extra-Purpose for ATT feature.

Steps:

  • Go to Extra-Purposes menu on the left, and click to Add Extra Purpose on the top-right corner.
  • Enter a name, description and select Floating for Type.
  • Save.
  • Got to your Notice, click on Edit and on the configuration section, add your new Floating Extra Purpose for ATT.
  • Save.

Features of AppConsentUIKit​

appconsent.consentGiven()

Return true if consent is given, false otherwise.

Present notice​

appconsent.presentNotice(force: true, viewController: self)

To display the CMP in modal mode on your ViewController.

appconsent.consentGiven(success: {
print("Success - Consent Given")
}, failure: { error in
print("Error: \(error)")
})

Present Geolocation notice​

appconsent.presentGeolocation(self)

To display geolocation CMP on your ViewController

appconsent.geolocationConsentGiven()

Return true if consent is given, false otherwise.

appconsent.geolocationConsentGiven(success: {
print("Success - Consent Given")
}, failure: { error in
print("Error: \(error)")
})

Consentable allowed - objectId​

appconsent.consentableAllowed(objectId: "1")

Return true if consentable with objectId = 1 is allowed, false otherwise.

Consentable allowed - iabId​

appconsent.consentableAllowed(iabId: "1")

Return true if consentable with iabId = 1 is allowed, false otherwise.

Consentable allowed - extraId​

appconsent.consentableAllowed(extraId: "1")

Return true if consentable with extraId = 1 is allowed, false otherwise.

Stack allowed​

appconsent.stackAllowed(iabId: "1")

Return true if consentable with iabId = 1 is allowed, false otherwise.

Vendor allowed - iabId​

appconsent.vendorAllowed(iabId: "1")

Return true if consentable with iabId = 1 is allowed, false otherwise.

Vendor allowed - extraId​

appconsent.vendorAllowed(extraId: "1")

Return true if consentable with extraId = 1 is allowed, false otherwise.

All Consentables allowed​

appconsent.allConsentablesAllowed()

Return true if all consentables are allowed, false otherwise.

All Stacks allowed​

appconsent.allStacksAllowed()

Return true if all stacks are allowed, false otherwise.

All Vendors allowed​

appconsent.allVendorsAllowed()

Return true if all vendors are allowed, false otherwise.

User Accept All​

appconsent.userAcceptAll()

This is a combination of allConsentablesAllowed , allStacksAllowed, allVendorsAllowed Return true if all of these are true otherwise false.

appconsent.setConsentableConsents(values: ["1": .allowed], success: {
print("Success")
}, failure: { error in
print("Error: \(error)")
})

Set consentables status with an iabId.

caution

Key must be an iabId, not an objectId. .

note

This method doesn’t send request to the server.

appconsent.setExtraConsentableConsents(values: ["aaa": .allowed], success: {
print("Success")
}, failure: { error in
print("Error: \(error)")
})

Set consentables status with extraId.

caution

Key must be an extraId, not an objectId.

note

This method doesn’t send request to the server.

Check for update​

appconsent.checkForUpdate({ value in
print("Success: \(value)")
}, failure: { error in
print("Error: \(error)")
})

Check if consent must be updated (new gvl version, new consentables…)

Clear consents​

appconsent.clearConsent()

Clear consents on NSUserDefaults, but not on server.

Set external data​

appconsent.setExternalData(shipData: ACShipData, success:, failure:)

Set external data with ACShipData model and send it to server.

Set externalIds​

appconsent.setExternalIds(externalIds: [String: String])

You can setExternalIds. Behind the scene, externalIds are stored in our cache Framework. If you want, you can save it to our server like this:

appconsent
.setExternalIds(externalIds: [String: String])
.saveExternalIds { state, configuration in
print(state ?? "state nil")
print(configuration ?? "configuration nil")
} failure: { error in
print(error.localizedDescription)
}

Get externalIds​

appconsent.getExternalIds() ->[String, String]

Retrieve the externalIds set before.

Open App Settings​

appconsent.openAppSettings() 

Open App Consent settings in the general tab.

App Tracking is available​

appconsent.appTrackingIsAvailable() ->Bool

Check if your device supports App Tracking Transparency.

App Tracking Authorization​

appconsent.appTrackingAuthorizationGiven() ->ACATTAuthorizationGiven

Check if App Tracking Transparency has been given.

App Tracking Request​

appconsent.appTrackingRequestAuthorization(_ completion: ((ACATTAuthorizationStatus)->Void)?)

Request user authorization. The ATT popup will be display.

note

The process to display ATT Popup is automatically integrated in AppConsentUIKit when user saves his consent.

Save ATT floating purpose​

appconsent.saveATTFloatingPurpose(with value: Bool, _ completion: ACResultVoidHandler?)

Save the ATT user choice and send it to our server.

Floating purpose allowed​

appconsent.floatingPurposeAllowed(extraId: String) ->Bool

Check if floating purpose is allowed.

note

You need to call checkForUpdate method before calling the above method to stay up to date.

Display ATT if needed​

appconsent.displayATTIfNeeded(_ completion: ((ACATTAuthorizationStatus)->Void)?)

For migrating existing users, you must call this method to display ATT popup without redisplaying CMP.

note

ATT Popup will only display if user's device supports ATT, user gave his consent, purpose 1 is true and the ATT popup has not yet been displayed.

caution

After that, you need to call new saveATTFloatingPurpose(with value: Bool, _completion: ACResultVoidHandler?) method to send user's choice on our server.

Delegate basic implementation​

Presenting a notice also takes a delegate parameter. It is an object conforming to the AppConsentDelegate protocol. Here are the main methods you'll need to implement.

appconsent.delegate = self

// called when the consent has been given
func appConsentDidFinish() {
print("consent did finish")
}

// called in case of error
func appConsentDidFail(_ error: Error) {
print("consent did fail: \(error.localizedDescription)")
}

func appConsentWillAppear() { ... }
func appConsentDidAppear() { ... }
func appConsentWillDisappear() { ... }
func appConsentDidDisappear() { ... }