iOS Swift SDK
Swift quickstart for the Amba SDK — Swift Package Manager install, Amba.configure, Amba.events.track, Sign in with Apple, and APNs push registration in under 10 minutes.
Amba for iOS is a Swift Package distributed via layers/amba-sdk-ios. Single import; everything else in this guide assumes you've added it to your target.
Supported platforms: iOS 14+, macOS 12+, tvOS 14+, watchOS 7+.
1. Install via Swift Package Manager
In Xcode
File → Add Package Dependencies… → enter:
Pick the dependency rule Up to Next Major with 1.0.0, then add the Amba product to your app target.
In Package.swift
The package's .binaryTarget resolves to a prebuilt AmbaCoreFFI.xcframework.zip published as a release asset on each tagged version — first build downloads ~12 MB, subsequent builds use Xcode's cache.
2. Configure at app launch
For UIKit, do the same in application(_:didFinishLaunchingWithOptions:):
Don't ship a hard-coded key. Inject AMBA_API_KEY via your .xcconfig, an Info.plist build-setting, or arkana — and reference it via Bundle.main.object(forInfoDictionaryKey:) or your secrets framework.
3. First sign-in (anonymous + Sign in with Apple)
Amba.events.track is authenticated server-side — the request needs a session token. Sign in (anonymously is fine) before the first track call:
4. First event
Once a session exists, track engagement events:
Amba.events.track is async throws — wrap in a Task { } from UI code, or await directly from another async context.
Sign in with Apple
Add the Sign in with Apple capability in Xcode → Signing & Capabilities before the first build.
5. Register for APNs push
Add the Push Notifications capability + Background Modes → Remote notifications in Xcode before building. Upload your APNs auth key (or .p8) to the amba console once per bundle ID.
6. First collection insert
The Swift SDK uses Codable for typed reads + writes:
7. AI proxy
Construct an AmbaClient directly (testing / multi-tenant)
For tests or multi-tenant apps, instantiate AmbaClient directly instead of using the singleton facade:
Tests can inject a mock conforming to AmbaCoreFfiProtocol via the internal initializer.
PrivacyManifest
The SDK ships PrivacyInfo.xcprivacy declaring its data-collection categories per Apple's PrivacyManifest spec. App Store review aggregates this with your app's own manifest — you don't need to copy entries from the SDK into yours.
Common pitfalls
Amba.configurenot called before any otherAmba.*access throwsAmbaSwiftError.notConfigured. Configure ininitof your@mainApp /application:didFinishLaunchingWithOptions:.- XCFramework not building for simulator — the prebuilt xcframework includes simulator + device slices for both arm64 and x86_64. If
swift buildfails with "no compatible binary for the current platform," your Xcode is older than 15.0 and can't link the new xcframework format — upgrade Xcode. - APNs token registered but no delivery — verify the APNs auth key in the amba console matches the bundle ID Xcode signed your app with. The token is valid; the server-side lookup fails 404 if bundle IDs drift.
- Sign in with Apple identity token expired —
credential.identityTokenis short-lived. Always pass it toAmba.auth.signInWithAppleimmediately; don't cache and reuse. - Background task running past app foreground — if
Amba.configurewas called in a now-deallocated context, the amba core's HTTP client survives but its observer hooks may be invalidated. Always re-checkAmba.isAuthenticatedbefore issuing background calls.
See also
- Client API reference — HTTP endpoint reference for every namespace.
- Code samples — same operations side-by-side with the other 7 SDKs.
- Push notifications — campaign API, scheduling, fan-out.
- SDK source:
layers/amba-sdk-ios(Swift Package Manager mirror).