Skip to content
Feature flags

iOS SDK

Evaluate feature flags

Read customer-targeted flags synchronously and update host UI when evaluations change.

Read a feature flag

Roll out a guided firmware update experience to selected customers. Feature flags load automatically after BTX has a customer identity. Reads are synchronous and use your fallback until the first evaluation is available or when a key is unknown.

Synchronous read
let useGuidedUpdater = BTX.featureFlags.isEnabled(
    "firmware-update-v2.enabled",
    fallback: false
)

Choose a fallback that keeps the host app safe when the network is unavailable or an evaluation has not loaded yet.

01

Update UI when flags change

Observe the shared flag object and pass in your app’s existing update flows. Keep the same battery, connection, and firmware compatibility checks in both flows.

Firmware update entry
import SwiftUI
import BTXClientKit

struct FirmwareUpdateEntry: View {
    @ObservedObject private var flags = BTX.featureFlags
    let startGuidedUpdate: () -> Void
    let startStandardUpdate: () -> Void

    var body: some View {
        let guided = flags.isEnabled("firmware-update-v2.enabled", fallback: false)

        Button(guided ? "Update with guide" : "Update firmware",
               systemImage: "arrow.down.circle") {
            if guided {
                startGuidedUpdate()
            } else {
                startStandardUpdate()
            }
        }
    }
}

For a host-owned model, use BTX.featureFlags.onChange and retain its returned cancellable for as long as you want updates.

02

Refresh explicitly

From an async main-actor context, refresh when the product flow needs a current evaluation immediately after an external change. Handle transport errors in the host.

Refresh
let state = try await BTX.featureFlags.refresh()