Consent Manager
1. Choose your type of installation
CocoaPods
1.Add following line into your Podfile
pod 'StackConsentManager', '~> 1.0.1'
2.Run pod install
2. Synchronize
Default
Consent manager SDK can be synchronized at any moment of application lifecycle. We recommend to synchronize it at application launch. Multiple synchronization calls are allowed.
Import StackConsentManager/StackConsentManager.h
in AppDelegate.m
import StackConsentManager
-application:didFinishLaunchingWithOptions:
.
Required parameter is appKey
- Appodeal API Key.
Optional parameters are customParameters
(string - any dictionary of custom parameters) and completion
(block that invokes after synchronization)
/// Initialisation class YourAppDelegate: AppDelegate { override func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]?) -> Bool { STKConsentManager.shared().synchronize(withAppKey: "Your app key") { [unowned self] error in error.map { print("Error while synchronising consent manager: \($0)") } guard STKConsentManager.shared().shouldShowConsentDialog == .true else { // Initialise SDK here return } // Load and present consent dialog } return true } }
After synchronization completion, you can receive information about the previous user consent and regulation zone. Before synchronization these parameters are undefined
// Check regulation let regulation = STKConsentManager.shared().regulation // Check consent status let status = STKConsentManager.shared().consentStatus // Available after first show (synchronisation is required) let consentString = STKConsentManager.shared().iabConsentString
Advanced
You can force consent manager to write iAB keys in NSUserDefaults
by setting up storage property before synchronization to STKConsentDialogStorageUserDefaults
SDK does not remove iAB keys from NSUserDefaults and only overrides them
// Store IAB strings in user defaults // should be called before synchronize STKConsentManager.shared().storage = .userDefaults
You can register yourself as a vendor before synchronization.
Parameter | Type | Description |
---|---|---|
id | Integer | iAB id. If you are not registered as iAB vendor you can use custom id |
name | String | Display name. Will be displayed in the consent window |
status | String | Custom string to check consent result for the concrete vendor |
purposesIds | Array of integers | iAB purposes ids array |
featuresIds | Array of integers | iAB features ids array |
legIntPurposeIds | Array of integers | iAB leg int purposes ids array |
// Register custom vendor (will be displayed on consent window) // should be called before synchronize STKConsentManager.shared().registerCustomVendor { builder in let _ = builder .appendPolicyURL(URL(string: "https://cmg.com/privacy")!) .appendName("My app") .appendBundle("com.app.bundle") .appendPurposesIds([1, 2, 3]) .appendFeaturesIds([5, 6]) .appendLegIntPurposeIds([1]) }
3. Consent window
SDK allows to call consent window api only after synchronization
After SDK synchronized, you can load the consent window. Loading allowed in any regulation zone and independent from previous consent.
class YourViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() STKConsentManager.shared().loadConsentDialog { [unowned self] error in error.map { print("Error while loading consent dialog: \($0)") } guard let controller = self.window?.rootViewController, STKConsentManager.shared().isConsentDialogReady else { // Initialise SDK here return } STKConsentManager.shared().showConsentDialog(fromRootViewController: controller, delegate: self) } } }
You can check that the consent window is ready or not
// Indicates that consent window ready to present let isReady = STKConsentManager.shared().isConsentDialogReady
After consent window Is ready you can present it from the top view controller
// Show consent dialog STKConsentManager.shared().showConsentDialog(fromRootViewController: controller, delegate: self)
Handling presentation callbacks
/// Get consent manager presentation callbacks class YourViewController: UIViewController, STKConsentManagerDisplayDelegate { // MARK: STKConsentManagerDisplayDelegate func consentManagerWillShowDialog(_ consentManager: STKConsentManager) {} func consentManager(_ consentManager: STKConsentManager, didFailToPresent error: Error) { // Something went wrong initializeAppodealSDK() } func consentManagerDidDismissDialog(_ consentManager: STKConsentManager) { // Resume app initializeAppodealSDK() } }
4. Appodeal SDK initialisation
func initializeAppodealSDK() { guard let consent = STKConsentManager.shared().consent else { let consent = STKConsentManager.shared().consentStatus != .nonPersonalized Appodeal.initialize( withApiKey: AppodealConstants.key, types: AppodealConstants.adTypes, hasConsent: consent ) return } Appodeal.initialize( withApiKey: AppodealConstants.key, types: AppodealConstants.adTypes, consentReport: consent ) }
You can use our demo app as a reference project.
5. Error handling
All returned errors are NSError instances with custom codes:
Code | Description |
---|---|
STKConsentManagerErrorInternal | Error on SDK side. Includes JS-bridge or encoding/decoding errors |
STKConsentManagerErrorNetworking | HTTP errors |
STKConsentManagerErrorInconsistent | Incorrect SDK API usage |
STKConsentManagerErrorUnknown | Any other errors |