iOS SDK (Swift)

Native Swift SDK fuer iOS 15+ und iPadOS mit SwiftUI-Unterstuetzung.

Systemvoraussetzungen

Swift Version5.9+
iOS Deployment TargetiOS 15.0+
Xcode Version15.0+

Installation

Swift Package Manager

Package.swift
dependencies: [
    .package(url: "https://github.com/breakpilot/consent-sdk-ios.git", from: "1.0.0")
]

Oder in Xcode: File → Add Package Dependencies → URL eingeben

Grundlegende Verwendung

AppDelegate.swift
import ConsentSDK

@main
class AppDelegate: UIResponder, UIApplicationDelegate {
    func application(
        _ application: UIApplication,
        didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
    ) -> Bool {

        // Consent Manager konfigurieren
        ConsentManager.shared.configure(
            apiEndpoint: "https://api.example.com/consent",
            siteId: "my-ios-app"
        )

        // Initialisieren
        Task {
            await ConsentManager.shared.initialize()
        }

        return true
    }
}

SwiftUI Integration

ContentView.swift
import SwiftUI
import ConsentSDK

struct ContentView: View {
    @StateObject private var consent = ConsentManager.shared

    var body: some View {
        VStack {
            if consent.hasConsent(.analytics) {
                AnalyticsView()
            }

            Button("Alle akzeptieren") {
                Task {
                    await consent.acceptAll()
                }
            }
        }
        .consentBanner() // Zeigt Banner automatisch
    }
}

// Consent Gate Modifier
struct ProtectedView: View {
    var body: some View {
        Text("Geschuetzter Inhalt")
            .requiresConsent(.marketing) {
                // Fallback wenn kein Consent
                Text("Marketing-Zustimmung erforderlich")
            }
    }
}

UIKit Integration

ViewController.swift
import UIKit
import ConsentSDK
import Combine

class ViewController: UIViewController {
    private var cancellables = Set<AnyCancellable>()

    override func viewDidLoad() {
        super.viewDidLoad()

        // Reaktiv auf Consent-Aenderungen reagieren
        ConsentManager.shared.$consent
            .receive(on: DispatchQueue.main)
            .sink { [weak self] state in
                self?.updateUI(consent: state)
            }
            .store(in: &cancellables)
    }

    private func updateUI(consent: ConsentState?) {
        if consent?.hasConsent(.analytics) == true {
            loadAnalytics()
        }
    }

    @IBAction func acceptAllTapped(_ sender: UIButton) {
        Task {
            await ConsentManager.shared.acceptAll()
        }
    }
}

Consent-Kategorien

// Verfuegbare Kategorien
enum ConsentCategory {
    case essential      // Immer aktiv
    case functional     // Funktionale Features
    case analytics      // Statistik & Analyse
    case marketing      // Werbung & Tracking
    case social         // Social Media Integration
}

// Consent pruefen
if ConsentManager.shared.hasConsent(.analytics) {
    // Analytics laden
}

// Mehrere Kategorien pruefen
if ConsentManager.shared.hasConsent([.analytics, .marketing]) {
    // Beide Kategorien haben Consent
}

API Referenz

MethodeBeschreibung
configure()SDK konfigurieren
initialize()SDK initialisieren (async)
hasConsent(_:)Consent fuer Kategorie pruefen
acceptAll()Alle Kategorien akzeptieren (async)
rejectAll()Alle ablehnen (async)
setConsent(_:)Spezifische Kategorien setzen (async)
showBanner()Banner anzeigen
exportConsent()Consent-Daten exportieren (DSGVO)