# iOS and Android

Install public releases through SwiftPM and Maven, configure dependencies, and connect Customer identity and usage relays.

[Web version](https://www.longplayai.com/docs/sdk/native)

<a id="ios"></a>

## iOS / macOS: SwiftPM

Requires Swift 6, iOS 16+ or macOS 12+. Resolve the latest stable release in the consuming Swift package and write an exact dependency to Package.swift. No GitHub repository access is needed.

**terminal**

```bash
SDK_VERSION="$(curl -fsS 'https://cdn.longplayai.com/sdk/longplay/stable?package=ios')" &&
swift package-registry set --scope tinkerlandai https://cdn.longplayai.com/sdk/ios &&
swift package add-dependency tinkerlandai.longplay --type registry --exact "$SDK_VERSION"
```

The command writes the exact package version. Add the Longplay product to your target dependencies in Package.swift:

**Package.swift**

```swift
.product(name: "Longplay", package: "tinkerlandai.longplay")
```

**terminal**

```bash
swift package resolve
swift package show-dependencies
```

Use `import Longplay` in application code. This uses Swift Package Registry: declare the dependency in a Swift package, then add that package's product to the Xcode app target. Commit Package.swift, Package.resolved and registry configuration; use swift package resolve --force-resolved-versions in CI. Resolve stable again explicitly when upgrading.

<a id="android"></a>

## Android: Maven

Requires minSdk 23, Java 17 and android.useAndroidX=true in gradle.properties. Resolve stable once at the project root into longplay-sdk.version; builds read that exact version without querying the network.

Add the Longplay repository to dependencyResolutionManagement.repositories in settings.gradle.kts, alongside google() and mavenCentral():

**settings.gradle.kts**

```kotlin
dependencyResolutionManagement {
    repositories {
        google()
        mavenCentral()
        maven {
            url = uri("https://cdn.longplayai.com/sdk/android")
            content { includeGroup("ai.tinkerland") }
        }
    }
}
```

**terminal**

```bash
SDK_VERSION="$(curl -fsS 'https://cdn.longplayai.com/sdk/longplay/stable?package=android')" &&
printf '%s\n' "$SDK_VERSION" > longplay-sdk.version
```

**app/build.gradle.kts**

```kotlin
val longplaySdkVersion = rootProject.file("longplay-sdk.version").readText().trim()

dependencyLocking {
    lockAllConfigurations()
}

dependencies {
    implementation("ai.tinkerland:longplay-sdk:$longplaySdkVersion")
}
```

**terminal**

```bash
./gradlew :app:dependencies --configuration debugRuntimeClasspath --write-locks
```

Import `ai.tinkerland.longplay.LongplayClient` in application code. Gradle reads the POM and module metadata and downloads the AAR; other dependencies remain on Google or Maven Central. Commit longplay-sdk.version and app/gradle.lockfile; omit --write-locks from normal builds. Resolve stable and update locks explicitly when upgrading.

<a id="identity"></a>

## Identity and usage after installation

- The stable SDK uses protocol 0.10 with https://api.longplayai.com and a Sandbox App and credentials issued by that production deployment. Sandbox still contains production data.
- Your backend issues the complete Customer session for its authenticated user: accessToken (Customer Token), refreshToken, customerId, sessionId, expiresAt and refreshExpiresAt. Use identify(session:) in Swift and identify(session) in Kotlin or React Native; call reset at logout. Customer creation, updates and credential issuance belong on the backend.
- The SDK refreshes directly with the Longplay API before Access expires, sharing one refresh across concurrent requests. Successful rotation preserves identity and business state. A lost reply retains the Refresh Token for the next attempt; a definitive authentication refusal or expired Refresh Token requires a new login. Refresh never automatically replays a business write.
- Clients use only the Access Token to read the current Customer's holdings and entitlements; a Refresh Token cannot access business endpoints. Passing only an Access Token leaves renewal to the host. Never ship a Server Key in the app.
- Relay usage through your own authenticated backend. The backend selects the Customer from the app session and calls a server SDK with its Server Key; retries retain the original idempotencyKey.

- [Customers and sessions](https://www.longplayai.com/docs/guides/customers.md)
- [Entitlements and usage](https://www.longplayai.com/docs/guides/entitlements.md)
