---
title: "iOS SDK"
source: https://docs.myappaffiliate.com/sdk-ios
docs: "MyAppAffiliate — Developer Documentation"
index: https://docs.myappaffiliate.com/llms.txt
---
# iOS SDK

The Swift SDK is the piece your app embeds. Zero runtime dependencies, iOS 15+.
Target: a working integration in under 30 minutes.

**Prompt for an AI coding agent**

```text
Integrate MyAppAffiliate into my project.

Documentation (read these first, they are the source of truth):
- Page: https://docs.myappaffiliate.com/sdk-ios.md
- Full docs index: https://docs.myappaffiliate.com/llms.txt

Task: Add the MyAppAffiliate iOS SDK to my app: install it with Swift Package Manager, configure it once at launch, attribute both Universal Links and manual referral codes, identify the user with the same id I pass to RevenueCat, and set the affiliate_id RevenueCat subscriber attribute before any purchase.

Rules:
- Follow the documented API exactly — no invented method names, endpoints, parameters or field names.
- Match the conventions already used in my codebase.
- Ask me for my SDK key and API base URL instead of guessing, and never hard-code secrets — read them from config/environment.
- Tell me afterwards which steps I still have to do by hand (dashboard settings, capabilities, webhook configuration).
```

## Install (Swift Package Manager)

In Xcode → **File → Add Package Dependencies…** and point at the SDK repo, or add to
`Package.swift`:

```swift
.package(url: "https://github.com/myappaffiliate/myappaffiliate-ios", from: "0.1.0")
```

## Configure (once, at launch)

```swift
import MyAppAffiliate

AffiliateSDK.configure(
  apiKey: "pk_live_…",                                   // your app's SDK key
  baseURL: URL(string: "https://api.myappaffiliate.com")!
)
```

## Attribute

**Universal Link** (add the Associated Domains capability — see [Go-Live](https://docs.myappaffiliate.com/go-live)):

```swift
// SwiftUI
.onOpenURL { url in AffiliateSDK.attribute(url: url) }
```

**Manual code** (reliable everywhere — a creator's "LUMI"):

```swift
AffiliateSDK.applyCode("LUMI")
```

## Identify the user

Use the **same** id you pass to RevenueCat (`Purchases.shared.logIn(...)`):

```swift
AffiliateSDK.identify(userId: yourUserId)
```

## Pass the affiliate into RevenueCat

Set this subscriber attribute **before** the purchase — it's what links subscription
revenue back to the creator:

```swift
import RevenueCat

if let affiliateId = AffiliateSDK.attributedAffiliateId() {
  Purchases.shared.attribution.setAttributes(["affiliate_id": affiliateId])
}
```

## API

| Call | Purpose |
|---|---|
| `AffiliateSDK.configure(apiKey:baseURL:)` | Initialize once at launch |
| `AffiliateSDK.attribute(url:)` | Record attribution from a Universal Link |
| `AffiliateSDK.applyCode(_:)` | Manual-code attribution fallback |
| `AffiliateSDK.identify(userId:)` | Bind your user id to the attribution |
| `AffiliateSDK.attributedAffiliateId()` | The attributed affiliate id (or `nil`) |

## Privacy

No IDFA, no fingerprinting, no cross-app tracking. The SDK stores only a generated
device id (Keychain) and the attributed affiliate id. Attribution is first-party and
deterministic.
