# iOS & Apple platforms

Install the Aplyna Swift source package in Xcode, verify the import, and send your first event from an async context.

## 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.

> **Source distribution**
> Install the downloadable local Swift package. A public remote SPM URL, CocoaPods pod and Carthage release are not currently published.

## 1. Install with Swift Package Manager

- [Download Swift SDK](https://aplyna.com/downloads/aplyna-ios.zip): ZIP containing Package.swift and the Aplyna source library.

1. Extract the archive. The package is in sdks/ios, with Package.swift at its root.
2. In Xcode, choose File → Add Package Dependencies, then Add Local.
3. Choose the extracted ios folder.
4. 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

### Swift

```
import Aplyna
```

Add 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

### Swift · async integration

```
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

### Swift

```
// After the user revokes tracking consent:
try await client.setConsent(false)

// For diagnostics, inspect the local queue count:
let pending = await client.pendingEventCount
```

Revocation 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.

## Onboarding versus purchases

> **No purchase capability is needed for an onboarding event**
> The onboarding quickstart sends telemetry and fetches configuration. Actual App Store purchases are a separate StoreKit integration with store configuration and verification requirements. A design preview or trial_started event does not validate a purchase.

## Next steps

- [Connect existing onboarding](https://aplyna.com/docs/existing-onboarding): Assignment, exposure and visible-step callbacks.
- [Visual builder & SwiftUI](https://aplyna.com/docs/visual-builder): Render supported saved layouts using AplynaFlowView.
- [Offline behavior](https://aplyna.com/docs/configuration): Understand cached configuration, assignments and fallbacks.
