Swift Integration

Current native iOS Persona guide covering OnairosConfig, createConnectButton, and Swift connector customization.

Updated 19 March 2026
swiftiosmobilepersona

Swift Integration

Use the native Swift SDK when you want the Persona flow directly inside an iOS app without going through React Native or Flutter.

Use the native config surface

The current Swift SDK is config-driven. Set up OnairosConfig, call OnairosSDK.shared.initialize(config:), and create a UIButton with createConnectButton.

1. Add the Swift package

Add the package through Xcode with File → Add Package Dependencies and use:

https://github.com/onairos/onairos-swift-sdk

2. Configure and initialize the SDK

import UIKit
import OnairosSDK

let config = OnairosConfig(
    apiKey: "your_api_key",
    environment: .production,
    googleClientID: "your-google-client-id.apps.googleusercontent.com",
    platforms: [.chatgpt, .youtube, .linkedin],
    recommendedPlatforms: [.chatgpt, .youtube],
    urlScheme: "yourapp",
    appName: "YourApp"
)

OnairosSDK.shared.initialize(config: config)

3. Create and add the connect button

let button = OnairosSDK.shared.createConnectButton(text: "Connect your data") { result in
    switch result {
    case .success(let onboardingResult):
        switch onboardingResult {
        case .success(let data):
            print(data.apiURL)
            print(data.token)
            print(data.connectedPlatforms.keys)
        case .failure(let error):
            print(error.localizedDescription)
        }
    case .failure(let error):
        print(error.localizedDescription)
    }
}

view.addSubview(button)

Connector customization

  • platforms controls which connectors appear on the connection screen.
  • platforms preserves order. The first platform in the array is the default selected connector.
  • recommendedPlatforms adds the Highly Recommended badge without changing order.

Main config fields

FieldRequiredWhat it does
apiKeyYesYour developer API key.
urlSchemeYesThe custom URL scheme used for OAuth callbacks back into your app.
appNameYesThe app name shown inside the consent and onboarding UI.
platformsNoThe visible connector list in the order you want to present it.
recommendedPlatformsNoThe connectors that receive the recommendation badge.
googleClientIDNoUse this when you need YouTube / Google sign-in.

What success returns

On success the Swift SDK gives you OnboardingData. The most useful fields are:

FieldMeaning
apiURLThe returned Persona API URL
tokenShort-lived token for that returned API URL
userDataUser/session data collected in the flow
connectedPlatformsThe connectors that completed successfully
inferenceDataOptional extra inference payload when present

Manual fetch example

var request = URLRequest(url: URL(string: data.apiURL)!)
request.httpMethod = "POST"
request.setValue("Bearer \(data.token)", forHTTPHeaderField: "Authorization")
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.httpBody = try JSONSerialization.data(withJSONObject: [
    "Input": [
        "item1": ["text": "Example content", "category": "general"]
    ]
])

URLSession.shared.dataTask(with: request) { responseData, _, error in
    if let responseData = responseData {
        print(String(decoding: responseData, as: UTF8.self))
    }
}.resume()
Next step

Use Inference API if your Swift app will call the returned route itself.