iOS integration

This guide covers the complete iOS integration of Amply SDK.

Basic Setup

1

Add Dependency

Swift Package Manager

In Xcode: File → Add Package Dependencies and enter the repository URL.

Or in Package.swift:

Package.swift
dependencies: [
    .package(url: "https://github.com/anthropics/amply-sdk-ios", from: "0.1.7")
]

CocoaPods

In your Podfile:

Podfile
pod 'AmplySDK', '~> 0.1.7'

Then run pod install.

2

Initialize SDK

Initialize in your AppDelegate:

AppDelegate.swift
import UIKit
import AmplySDK

@main
class AppDelegate: UIResponder, UIApplicationDelegate {

    private static var amplySDK: Amply?

    func application(
        _ application: UIApplication,
        didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
    ) -> Bool {

        let config = AmplyConfig(
            appId: "your.app.id",
            apiKeyPublic: "your_public_key",
            apiKeySecret: "your_secret_key",
            defaultConfig: nil
        )

        AppDelegate.amplySDK = Amply(config: config)

        return true
    }

    static func getAmply() -> Amply? {
        return amplySDK
    }
}
3

SwiftUI App Lifecycle

For SwiftUI apps using @main App:

MyApp.swift
import SwiftUI
import AmplySDK

@main
struct MyApp: App {

    @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate

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

Configuration Options

Full Configuration

Configuration
let config = AmplyConfig(
    appId: "your.app.id",
    apiKeyPublic: "your_public_key",
    apiKeySecret: "your_secret_key",
    defaultConfig: nil,  // Optional: default campaign JSON
    configBaseUrl: "https://config.amply.tools",  // Optional: override
    backendBaseUrl: "https://api.amply.tools"     // Optional: override
)

Tracking Events

Basic Events

From View Controllers

From SwiftUI Views

Register Listener

Register in your app:

System Events

Listen for SDK system events:

circle-exclamation

Rate & Review

The SDK supports triggering App Store reviews via campaigns. On iOS:

  • Uses SKStoreReviewController.requestReview()

  • Follows Apple's guidelines for review prompts

  • No additional code needed - handled automatically by campaign actions

Get Dataset Snapshots

Get Recent Events

App Lifecycle

The SDK automatically handles app lifecycle for session management. For manual control:

Best Practices

  • Initialize in AppDelegate — Ensures SDK is ready before any view loads

  • Keep strong references — Listener adapters must be retained

  • Request ATT early — But respect user experience (don't prompt immediately)

  • Use async/await — SDK methods are async-friendly

  • Test on device — Some features require real device (IDFA, reviews)

Troubleshooting

chevron-rightSDK Not Initializinghashtag
  • Verify API keys are correct

  • Check network connectivity

  • Review console logs for errors

chevron-rightIDFA Always Emptyhashtag
  • Ensure ATT permission is granted

  • Check Info.plist has usage description

  • Test on real device (simulator has no IDFA)

chevron-rightEvents Not Sendinghashtag
  • Ensure SDK is initialized

  • Check network connectivity

  • Verify app has network permission

chevron-rightListener Not Receiving Eventshashtag
  • Keep strong reference to adapter objects

  • Verify listener is registered after SDK init

  • Check for deinit calls in adapter logs

Last updated