Consent Handling
Consent Status
Section titled “Consent Status”You can check the current consent status by calling:
let result = spConsentEngine.getConsentStatus(applicationId: "YOUR_APPLICATION_ID")let status = result.data
switch status {case .pending: // Show consent bannercase .collected: // Proceed normallycase .recollectionRequired: // Trigger re-consent flow}Consent Recollection Reason
Section titled “Consent Recollection Reason”When the SDK determines that consent needs to be recollected (for example, a consent update/re-consent flow), you can fetch the reason by calling:
let result = spConsentEngine.getConsentRecollectionReason(applicationId: "YOUR_APPLICATION_ID")let reason: SPConsentRecollectionReason? = result.data
if let reason { switch reason { case .expired: // Handle expired case .structureChanged: // Handle structure change }}If no recollection reason is available, reason will be nil.
SPConsentRecollectionReason
Section titled “SPConsentRecollectionReason”| Case | Raw value | Meaning |
|---|---|---|
expired | expired | Consent has expired and needs to be re-collected. |
structureChanged | structure_changed | Packages and services hash mismatch. |
Enum usage guidance
Section titled “Enum usage guidance”SDK enums are the authoritative representation for consent status and recollection reasons. The SDK guarantees the enum contract, but does not guarantee that raw string values remain stable.
Prefer enums in your app logic:
- Use
switchon enums - Avoid branching on raw string values
- Map to your own keys if needed
let myReasonKey: String? = { guard let reason else { return nil } switch reason { case .expired: return "MY_EXPIRED" case .structureChanged: return "MY_STRUCTURE_CHANGED" }}()Consent Status
Section titled “Consent Status”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 a Package Is Enabled
Section titled “Check If a Package Is Enabled”let result = spConsentEngine.getPackage( applicationId: "YOUR_APPLICATION_ID", packageId: "Package-Id-To-Find")
if let spPackage = result.data { if spPackage.enabled() { // Enable features }}This returns an SPDataMessage containing an optional SPPackageConsent. Check enabled() to determine user consent.
Collecting Consent
Section titled “Collecting Consent”do { let result = try spConsentEngine.showConsentBannerFor( applicationId: "YOUR_APPLICATION_ID", vc: vc ) if result.code != 200 { print("Error: \(result.msg)", result.error ?? "") }} catch { print("Error: \(error)")}This banner informs users about data collection and provides options to accept, deny, or customize consent.
Customization Options
Section titled “Customization Options”Users can customize their preferences via the Preference Center:
do { let result = try spConsentEngine.showPreferenceCenter( applicationId: "YOUR_APPLICATION_ID", in: vc ) if result.code != 200 { print("Error: \(result.msg)", result.error ?? "") }} catch { print("Error: \(error)")}Essential Services
Section titled “Essential Services”You can mark certain services as essential. These cannot be disabled by users.
Privacy Policy
Section titled “Privacy Policy”The Preferences screen includes a tab showcasing content related to the app’s privacy policy.
Data Requests
Section titled “Data Requests”Users can submit data requests via the Request Data section.