Prerequisites
- An application in Aplyna and its app-scoped SDK key.
- An Xcode toolchain supporting Swift 6; the package declares iOS 16+ and macOS 13+.
- Your native app project open in Xcode.
1. Install with Swift Package Manager
- Extract the archive. The package is in sdks/ios, with Package.swift at its root.
- In Xcode, choose File → Add Package Dependencies, then Add Local.
- Choose the extracted ios folder.
- Add the Aplyna library product to the application target that uses it. Keep the package folder available in your project checkout.
2. Import and build
import AplynaAdd the import to a Swift source file in your app target and choose Product → Build. A successful build confirms the target can resolve the SDK. If Xcode reports No such module, check target membership and the linked package product before changing your code.
3. Initialize the client
import Foundation
import Aplyna
// Create once and persist; reuse this ID across app launches.
let defaults = UserDefaults.standard
let installationID = defaults.string(forKey: "aplyna.installationID")
?? UUID().uuidString
defaults.set(installationID, forKey: "aplyna.installationID")
let client = AplynaClient(
baseURL: URL(string: "https://aplyna.com")!,
apiKey: "YOUR_APP_SDK_KEY",
installationID: installationID
)
// Run in an async context, after your consent flow permits tracking.
try await client.setConsent(true)
try await client.track(name: "app_opened")
try await client.flush()AplynaClient is an actor. Reuse the same client instead of constructing it for each event. Wrap throwing calls in your app's error handling and execute them in a Task or another async context. Do not regenerate installationID for every session.
4. Handle consent and delivery
// After the user revokes tracking consent:
try await client.setConsent(false)
// For diagnostics, inspect the local queue count:
let pending = await client.pendingEventCountRevocation clears queued telemetry. The client persists unsent events, sends batches of up to 100, and retries transient delivery failures twice within a flush call. Your application must call flush again later after a final failure; there is no background scheduler supplied by this source SDK.