A SwiftUI demo application showcasing the integration and functionality of the consentmanager CMP (Consent Management Platform) SDK v2 for iOS. This app demonstrates how to implement and interact with various consent management features.
For more information about the Consentmanager CMP SDK, visit consentmanager.net and our help documentation.
This demo app provides a comprehensive interface to test and validate the CMP SDK's functionality, including:
- Consent status checking
- Purpose and vendor management
- Consent string handling
- UI layer integration
-
CMPManager
: A singleton wrapper around the CMP SDK that handles:- SDK initialization and configuration
- Event handling (errors, UI open/close events)
- Notification broadcasting
-
ContentView
: The main view container that manages:- Loading state
- Consent WebView visibility
- Controls visibility
-
ConsentControlsView
: A SwiftUI interface providing buttons to interact with all major SDK features
-
Basic SDK Setup
- SDK initialization with custom configuration
- Event listener registration
- Error handling
-
Consent Management
- Check user consent status
- Get/Set consent string
- Import external consent strings
- Accept/Reject all consents
-
Purpose Management
- List all purposes
- Check specific purpose consent
- Enable/Disable individual purposes
- Get enabled/disabled purposes
-
Vendor Management
- List all vendors
- Check specific vendor consent
- Enable/Disable individual vendors
- Get enabled/disabled vendors
-
UI Integration
- Consent layer display
- Toast notifications for action feedback
- Loading states
- WebView integration
let cmpConfig = CmpConfig.shared.setup(
withId: "Your Code-ID goes here (13 characters)",
domain: "delivery.consentmanager.net",
appName: "CMPSDKv2DemoApp",
language: "IT"
)
// Check if user has made a choice
CMPManager.shared.cmpManager?.hasConsent()
// Accept all consents
CMPManager.shared.cmpManager?.acceptAll {
// Handle completion
}
// Reject all consents
CMPManager.shared.cmpManager?.rejectAll {
// Handle completion
}
// Enable specific purposes
CMPManager.shared.cmpManager?.enablePurposeList(["c52", "c53"])
// Enable specific vendors
CMPManager.shared.cmpManager?.enableVendorList(["s2790", "s2791"])
// Check specific consent
CMPManager.shared.cmpManager?.hasPurposeConsent("c53")
CMPManager.shared.cmpManager?.hasVendorConsent("s2789")
LoadingView
: Displays initialization progressConsentWebView
: Renders the CMP consent interfaceConsentControlsView
: Provides interactive buttons for all SDK featuresToastView
: Shows feedback messages for user actions
The app demonstrates proper event handling through:
- Error callbacks
- Open/Close events
- Button click tracking
- NotificationCenter broadcasts
- Always initialize the SDK before accessing any features
- Handle the consent WebView visibility through NotificationCenter observers
- Implement proper error handling for all SDK operations
- Use the async/await pattern for consent string imports
- Maintain a single instance of CMPManager throughout the app lifecycle
- CmpSdk framework version 2.5.3
This demo app is designed to showcase the integration patterns and available features of the CMP SDK. In a production environment, you would need to:
- Add proper error handling
- Implement persistence if required
- Add proper loading states
- Handle edge cases
- Add proper logging