iOS SDK

The Swift SDK is the piece your app embeds. Zero runtime dependencies, iOS 15+.

Set this up with your AI coding agent
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, start it with the one-line SwiftUI modifier (or MyAppAffiliate.start in UIKit), and identify the user with the same id my billing provider reports.

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 instead of guessing, and never hard-code it — read it from config/environment.
- Do NOT set an API base URL anywhere. Every SDK compiles the production host in; a staging or self-hosted host belongs in a build setting, not in code.
- 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.3.0")

1. Start it

SwiftUI — one line. The modifier starts the SDK and forwards incoming Universal Links to it, so you write no .onOpenURL of your own:

Swift
import MyAppAffiliate
 
@main
struct MyApp: App {
  var body: some Scene {
    WindowGroup {
      ContentView().myAppAffiliate(apiKey: "pk_live_…")
    }
  }
}

UIKit / manual. Start at launch and forward links yourself:

Swift
MyAppAffiliate.start(apiKey: "pk_live_…")
// in application(_:open:options:) or scene(_:openURLContexts:)
MyAppAffiliate.attribute(url: incomingURL)

You never pass an API URL — the host is compiled in.

Keeping the key out of source

Put it in Info.plist under MyAppAffiliateAPIKey (set from a build setting to vary it per scheme) and the call takes no arguments at all:

Swift
MyAppAffiliate.start()
// or: ContentView().myAppAffiliate()

2. Identify the user

Call this once you know who the user is. The id must be the same string your billing provider reports back to us — RevenueCat's logIn(...) id, Adapty's customer user id, Superwall's app user id, or your Stripe metadata value. See Billing & Webhooks.

Swift
MyAppAffiliate.identify(userId: yourUserId)

That's the whole integration. There is no third step — in particular, you do not need to set an affiliate_id subscriber attribute anywhere; attribution joins on the user id.

Optional

Creator codes — a "Got a code?" field. Works with no deep-link setup at all, which makes it the reliable fallback when Associated Domains are not configured:

Swift
MyAppAffiliate.applyCode("LUMI")

Read the attribution for your own UI or analytics:

Swift
let affiliateId = MyAppAffiliate.attributedAffiliateId()  // String?

Staging or self-hosted API, and debug logging:

Swift
MyAppAffiliate.start(
  apiKey: "pk_live_…",
  options: .init(apiBaseURL: URL(string: "https://staging.example.com"), debug: true)
)

(Or set MyAppAffiliateAPIBaseURL in Info.plist and pass nothing.)

On logout or a data-erasure request:

Swift
MyAppAffiliate.reset()

What start does for you

  • Generates and persists a device id in the Keychain (survives reinstalls).
  • Claims the referral from a Universal Link when one opened the app.
  • Retries a referral an earlier launch captured but failed to send — a first launch is exactly when a device is most likely offline.
  • On a fresh App Store install with no link to go on, asks the API for a deferred match. This is what makes link-driven installs attributable at all; the App Store drops the claim token, so the server matches on a hashed IP and a short time window.

Universal Links need the Associated Domains capability — see Go-Live. Skip it and creator codes still work.

API

CallPurpose
MyAppAffiliate.start(apiKey:)Start once at launch (key optional if in Info.plist)
MyAppAffiliate.identify(userId:)Bind your user id to the attribution
.myAppAffiliate(apiKey:)SwiftUI modifier: start + link handling in one line
MyAppAffiliate.attribute(url:)Claim a referral from a link (UIKit)
MyAppAffiliate.applyCode(_:)Creator-code entry
MyAppAffiliate.attributedAffiliateId()The attributed affiliate id (or nil)
MyAppAffiliate.reset()Clear all persisted SDK state

Every call is a safe no-op before start, and every network failure is silent — nothing throws into your app.

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.