01
Install from pinned source
Vendor or submodule a reviewed Pact revision, then add that directory as a local package in Xcode. The package supports iOS 15 and newer.
swift
dependencies: [
.package(path: "Vendor/pact")
]
// Target dependency:
.product(name: "PactConsent", package: "pact")02
Create the native client
The bundle ID is an approved deployment binding. The consent scope—not the bundle ID—groups compatible web and mobile properties under one policy version.
swift
import PactConsent
let consent = PactConsentClient(configuration: PactConfiguration(
baseURL: URL(string: "https://consent.example.com")!,
tenantId: "acme",
consentScopeId: "customer-account",
policyVersion: "policy-2026-08",
region: "EU",
binding: .ios(bundleIdentifier: "com.example.app"),
purposes: [
.init(id: .essential, displayName: "Essential", description: "Required", required: true),
.init(id: .analytics, displayName: "Measurement", description: "Understand product use"),
.init(id: .marketing, displayName: "Advertising", description: "Relevant advertising")
]
))03
Use managed SwiftUI
swift
import PactConsent
import SwiftUI
struct PrivacySettingsView: View {
@ObservedObject var consent: PactConsentClient
var body: some View {
PactPrivacyButton(client: consent)
// Or present PactConsentView(client: consent) directly.
}
}04
Use the headless API
The client owns state and evidence while your application owns every visible element.
swift
consent.deny([.marketing])
consent.save([.analytics: true, .marketing: false])
if consent.isAllowed(.analytics) {
startMeasurement()
}05
Link only after customer authentication
Your backend authenticates the person and returns a five-minute Pact link credential. The app never sends Pact an email address or public account ID.
swift
let credential = try await customerAPI.pactLinkCredential()
try await consent.link(with: credential)
// Pull another approved device's latest compatible decision.
try await consent.refresh()Anonymous choices remain in UserDefaults until linking. The linked session is held in Keychain and queued evidence retries after transient failures.