iOS SDK
Overview
The Secure Privacy Consent Management SDK provides iOS developers with an easy way to manage user consent within their applications. By integrating this SDK, you can ensure compliance with privacy regulations while giving users control over their data preferences.
Getting Started
Obtain Your Application ID
To use the Secure Privacy SDK, you need an Application ID. Sign up for a free trial at Secure Privacy to get your Application ID.
Installation
To begin using the Secure Privacy SDK for iOS, you can integrate it using either XCFramework or CocoaPods.
Option 1: Using XCFramework
- Download the SPMobileConsent.xcframework.
- Open your Xcode project.
- Drag and drop
SPMobileConsent.xcframework
into your project. - Go to Targets → Frameworks, Libraries, and Embedded Content.
- Ensure
SPMobileConsent.xcframework
is listed, and set to Embed & Sign. - Open your Xcode project.
- Drag n Drop
SPMobileConsent.xcframework
in your project - Go to Targets -> Frameworks, Libraries, and Embedded Content. Make sure the
SPMobileConsent.xcframework
is listed and embedded is marked asEmbed & Sign
Option 2: Using CocoaPods
- Add the following line to your Podfile:
pod 'SecurePrivacyMobileConsent'
- Run the following command:
pod install
- Open the
.xcworkspace
file to launch your project with the integrated SDK.
Initialization
To initialize the SDK, call the following method in your app’s entry point (typically in AppDelegate.swift
or SceneDelegate.swift
):
import SPMobileConsent
let result = await SPConsentEngineFactory.initialise( key: SPAuthKey( applicationId: Config.APPLICATION_ID, secondaryApplicationId: Config.SECONDARY_APPLICATION_ID ))let spConsentEngine = result.data
This will set up the SDK and enable access to its features.
Consent Status
You can check the current consent status by calling:
let consentStatus = spConsentEngine.getConsentStatus(applicationId: Config.APPLICATION_ID)
Consent States
The SDK supports three consent states:
- Collected: Consent has already been obtained.
- Pending: Consent needs to be collected.
- RecollectionRequired: Consent needs to be re-collected.
Check if User has Enabled the Package
To check if a specific package has been marked as enabled by the user upon giving consent, you can call:
if let packageResult = spConsentEngine.getPackage(applicationId: Config.APPLICATION_ID, packageId: "Package-Id-To-Find") { if let spPackage = packageResult.data as? SPPackageConsent { if spPackage.enabled() { //enable features } }}
This would return a SPDataMessage containing the SPMobilePackage only if the user has consented. Otherwise, it would return null.
Collecting Consent
To launch the consent collection popup, use the following method:
consentEngine?.showConsentBanner(in: self)
This popup will inform users about the SDK and provides them with options to agree to all, deny to all or customise their consent preferences.
Additionally, you can call the following method to display the secondary consent banner:
spConsentEngine.showSecondary(in: self);
Listening to Consent Events
You can listen to consent events by SPConsentEventDelegate:
class MobileConsentEventDelegate: SPConsentEventDelegate{ var applicationId: String = Config.APPLICATION_ID
func onConsentAction(data: SPMobileConsent.SPDataMessage<SPMobileConsent.SPConsentEvent>) { //Custom logic }}
Add a delegate to listen to consent events
spConsentEngine.addDelegate(forCode: MOBILE_CONSENT_EVENT_CODE, delegate: eventDelegate)
Remove delegate
spConsentEngine.removeDelegate(forCode: MOBILE_CONSENT_EVENT_CODE)
Here, MOBILE_CONSENT_EVENT_CODE
is a unique code you can use to add/remove delegate and track updates on consent actions.
Additional Way to Listen to Consent Events:
As an additional way to listen to consent events, you can now observe consent events using the following method:
spConsentEngine.addObserver(code: YOUR_UNIQUE_EVENT_CODE, observer: self, callback: { event in //Custom logic})
spConsentEngine.removeObserver(forCode: YOUR_UNIQUE_EVENT_CODE)
Event Codes
When using the SDK to listen to consent events, it’s important to understand how event codes work.
Event codes are unique identifiers that is used to register/unregister consent event delegates and observers. The event code helps distinguish between different consent events, particularly when dealing with multiple delegates, observers or consent events across different ViewControllers or classes.
Customization Options
Users have the option to customize their preferences. When they click the customization button, they will be directed to the Preference Center, where they can:
- View a list of frameworks and their services.
- Enable or disable consent for specific services.
To display the preference center directly, simply call:
spConsentEngine.showPreferenceCenter(applicationId: Config.APPLICATION_ID, in: self)
Clearing Session
To clear the session, call clearSession()
. This method is useful when you want to ensure that all local session-specific sdk data is cleared. It is typically used when a user logs out or resets their preferences.
spConsentEngine.clearSession()
Handling Unique Client ID (optional)
Each time the app is installed (fresh install) or during a new session, Secure Privacy Mobile Consent SDK generates a unique clientId for the user. This clientId can be retrieved by calling the following method.
let clientId = spConsentEngine?.getClientId(applicationId: Config.APPLICATION_ID)
This clientId
can be used to associate the user’s consent with internal identifiers within your app or backend systems. You can also use this clientId for custom user identification and to ensure accurate tracking of consent preferences.
Essential Services
You can mark certain services as essential. These services will not be optional for the user to deny, ensuring compliance with the app’s required functionalities.
Privacy and Cookie Policy
The Preferences screen also includes tabs showcasing content related to the app’s privacy and cookie policies. This ensures users have access to essential information regarding their data handling.