Skip to main content

iOS Integration

On this page you'll find integration guides for iOS platforms. Use the tabs to pick your framework.

Swift Integration

Consent URL: https://consent.example.com/consent?cr_id=...&mobile_app=true&app_scheme=myapp

Basic Implementation

import UIKit

class ConsentViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()

let button = UIButton(type: .system)
button.setTitle("Open Consent", for: .normal)
button.addTarget(self, action: #selector(openConsent), for: .touchUpInside)
button.frame = CGRect(x: 100, y: 100, width: 200, height: 50)
view.addSubview(button)
}

@objc func openConsent() {
let consentURL = "https://consent.example.com/consent?cr_id=...&mobile_app=true&app_scheme=myapp"
if let url = URL(string: consentURL) {
UIApplication.shared.open(url)
}
}
}

Configure Info.plist:

<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>com.example.myapp</string>
<key>CFBundleURLSchemes</key>
<array>
<string>myapp</string>
</array>
</dict>
</array>

Handle callbacks in AppDelegate.swift:

import UIKit

@main
class AppDelegate: UIResponder, UIApplicationDelegate {

func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {

if url.scheme == "myapp" && url.host == "consent" {
let components = URLComponents(url: url, resolvingAgainstBaseURL: true)
let status = components?.queryItems?.first(where: { $0.name == "status" })?.value
let receiptId = components?.queryItems?.first(where: { $0.name == "receiptId" })?.value
let crId = components?.queryItems?.first(where: { $0.name == "crId" })?.value

print("Consent completed with status: \(status ?? "unknown")")

if let receiptId = receiptId, let crId = crId {
print("Receipt ID: \(receiptId), CR ID: \(crId)")
}

return true
}

return false
}
}