iOS (Swift)
Installation, configuration, event tracking, and full API reference for the iOS (Swift) SDK.
Requirements
- iOS 14.0+
- Xcode 15+
- Swift concurrency (async/await)
1. Install
Swift Package Manager
// In Xcode: File → Add Package Dependencies…// Or in Package.swift:.package(url: "https://github.com/app-sprint/appsprint-ios.git", from: "0.1.0")
2. Configure
import AppSprintSDK// Call as early as possible — App.init() or AppDelegateawait AppSprint.shared.configure(AppSprintConfiguration(apiKey: "as_live_xxxxx"))
Must run on the main thread (@MainActor). The SDK automatically tracks the install on first launch and flushes any queued events.
Configuration options
| Option | Type | Default | Description |
|---|---|---|---|
| apiKey | String | — | Your live API key (starts with as_live_). |
| apiURL | URL | https://api.appsprint.app | Override the API base URL for testing. |
| enableAppleAdsAttribution | Bool | true | Fetch the AdServices attribution token on first launch. |
3. Track events
// Standard eventawait AppSprint.shared.sendEvent("login")
// Revenue eventawait AppSprint.shared.sendEvent("purchase", revenue: 9.99, currency: "USD")
// Custom event with parametersawait AppSprint.shared.sendEvent("level_complete", parameters: ["level": 5,"score": 1200,])
Supported event types
loginsign_upregisterpurchasesubscribestart_trialadd_to_cartadd_to_wishlistinitiate_checkoutview_contentview_itemsearchsharetutorial_completelevel_startlevel_completecustomUse custom with a name parameter for any event not in this list.
4. Read attribution
After configure() completes, the SDK caches the attribution result from the install response. Access it synchronously:
let attr = AppSprint.shared.getAttribution()print(attr?.source) // "apple_ads", "fingerprint", or "organic"print(attr?.confidence) // 0.0–1.0print(attr?.campaignName) // Campaign name if available
| Field | Description |
|---|---|
| source | "apple_ads", "fingerprint", or "organic" |
| confidence | Match confidence from 0.0 to 1.0 |
| campaignName | Campaign name (if attributed to an ad) |
| utmSource | UTM source from the tracking link |
| utmMedium | UTM medium from the tracking link |
| utmCampaign | UTM campaign from the tracking link |
API reference
configure(_:)
→ asyncInitialize the SDK. Auto-tracks install on first launch and flushes queued events.
await AppSprint.shared.configure(AppSprintConfiguration(apiKey: "…"))
sendEvent(_:revenue:currency:parameters:)
→ asyncSend an event. Queued automatically if offline or not yet initialized.
await AppSprint.shared.sendEvent("purchase", revenue: 9.99, currency: "USD")
flush()
→ asyncRetry all queued events immediately.
await AppSprint.shared.flush()
clearData()
Clear all cached state, queue, and disabled flag. Use to reset the SDK.
AppSprint.shared.clearData()
getAppSprintId()
→ String?Returns the install ID, or nil before install tracking completes.
let id = AppSprint.shared.getAppSprintId()
getAttribution()
→ AttributionData?Returns cached attribution data from the install response.
let attr = AppSprint.shared.getAttribution()
isInitialized
→ BoolTrue once configure() has completed.
AppSprint.shared.isInitialized
sendTestEvent()
→ TestEventResultSend a diagnostic event. Returns success/message — use to verify connectivity.
let result = await AppSprint.shared.sendTestEvent()
setCustomerUserId(_:)
→ asyncAttach your own user ID. Sent to the API immediately if install is tracked, otherwise queued.
await AppSprint.shared.setCustomerUserId("user-123")
Offline behavior
- Events that fail to send are automatically queued in native storage (up to 100 events).
- The queue persists across app restarts.
- Queued events are retried automatically when
configure()completes, when the app moves to the background, or when you callflush(). - If a queued event receives a 401/403, the SDK disables itself and clears the queue.
Platform notes
- The SDK calls AdServices.AAAttribution.attributionToken() on iOS 14.3+ to detect Apple Search Ads installs. On older versions it falls back to the iAd framework.
- IDFA is only collected if the user has granted App Tracking Transparency permission. IDFV is always collected.
- configure() is annotated @MainActor — call it from the main thread or an async context that already runs on main.
- The event queue flushes automatically when the app moves to the background.
Integrations
Once the SDK is configured, connect revenue and ad-network integrations:
Troubleshooting
getAppSprintId() returns nil
configure() is async — the install network call may not have finished yet. Wait for configure() to complete before reading the ID.
Events not appearing in dashboard
Check that you are using a live API key (as_live_*). Call sendTestEvent() and inspect the result message.
SDK disabled after 401/403
The SDK disables itself permanently when the API key is rejected. Call clearData() and re-configure with a valid key.
Apple Ads attribution missing
Ensure AdServices.framework is linked. Test on a real device — the simulator does not return attribution tokens.
Connectivity test
let result = await AppSprint.shared.sendTestEvent()print("\(result.success) — \(result.message)")
Verification checklist
- Create a blank iOS app and add the Swift package.
- Call configure() in your App or AppDelegate entry point.
- Verify getAppSprintId() returns a value after first launch.
- Send login, purchase, and custom events — confirm they appear in the dashboard.
- Kill the app while offline, send an event, relaunch with connectivity — verify the event appears (queue flush).
- Call sendTestEvent() and confirm { success: true }.