Appfiliate Docs
appfiliate.io

iOS SDK (Swift)

Add affiliate install and purchase attribution to your iOS app with a lightweight Swift package.


Prerequisites

  • iOS 15.0 or later
  • Xcode 15 or later
  • Swift 5.9 or later
  • An Appfiliate account with an App ID and API Key (available at app.appfiliate.io)

Step 1: Add the Swift Package

In Xcode, go to File → Add Package Dependencies and enter the following repository URL:

Swift Package URL
https://github.com/appfiliate/appfiliate-ios-sdk

Set the version rule to 1.0.0 -- Next Major Version and click Add Package. Xcode will resolve the dependency and add it to your project.

Using Package.swift?

If you manage dependencies through a Package.swift file, add the dependency like this:
Package.swift
.package(url: "https://github.com/appfiliate/appfiliate-ios-sdk", from: "1.0.0")

Step 2: Configure and track install

Add the Appfiliate import and call configure() and trackInstall() at your app's entry point. Replace the placeholder values with the App ID and API Key from your Appfiliate dashboard.

SwiftUI App

MyApp.swift
import SwiftUI
import Appfiliate

@main
struct MyApp: App {
    init() {
        Appfiliate.configure(appId: "YOUR_APP_ID", apiKey: "YOUR_API_KEY")
        Appfiliate.trackInstall()
    }

    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}

UIKit AppDelegate

AppDelegate.swift
import UIKit
import Appfiliate

@main
class AppDelegate: UIResponder, UIApplicationDelegate {
    func application(
        _ application: UIApplication,
        didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
    ) -> Bool {
        Appfiliate.configure(appId: "YOUR_APP_ID", apiKey: "YOUR_API_KEY")
        Appfiliate.trackInstall()
        return true
    }
}

Step 3: Track purchases (optional)

To attribute revenue to affiliates, call trackPurchase() after every successful in-app purchase.

StoreKit 2

StoreManager.swift
import StoreKit
import Appfiliate

func purchase(_ product: Product) async throws {
    let result = try await product.purchase()

    switch result {
    case .success(let verification):
        let transaction = try verification.payloadValue

        Appfiliate.trackPurchase(
            productId: product.id,
            revenue: product.price,
            currency: "USD",
            transactionId: String(transaction.id)
        )

        await transaction.finish()

    case .userCancelled, .pending:
        break
    @unknown default:
        break
    }
}

Classic StoreKit (SKPaymentQueue)

PaymentObserver.swift
import StoreKit
import Appfiliate

func paymentQueue(
    _ queue: SKPaymentQueue,
    updatedTransactions transactions: [SKPaymentTransaction]
) {
    for transaction in transactions {
        switch transaction.transactionState {
        case .purchased:
            let productId = transaction.payment.productIdentifier
            let transactionId = transaction.transactionIdentifier ?? ""

            Appfiliate.trackPurchase(
                productId: productId,
                revenue: 9.99,
                currency: "USD",
                transactionId: transactionId
            )

            queue.finishTransaction(transaction)

        default:
            break
        }
    }
}

Important notes

No IDFA or ATT required

The Appfiliate SDK does not use the Advertising Identifier (IDFA) and does not require an App Tracking Transparency prompt. Attribution is handled through deterministic matching without device-level ad tracking.
  • trackInstall() is safe to call on every app launch. It only fires once per install.
  • trackPurchase() should be called after every successful in-app purchase to ensure accurate revenue attribution.
  • The SDK is under 200 KB with zero external dependencies.
  • Works alongside any other analytics or attribution provider.