iOS - Adapty SDK installation & configuration

Learn how to install and configure Adapty SDK and AdaptyUI SDK for iOS, essential for seamless integration of Adapty into your mobile app

Adapty comprises two crucial SDKs for seamless integration into your mobile app:

  • General AdaptySDK: This is a fundamental, mandatory SDK necessary for the proper functioning of Adapty within your app.
  • AdaptyUI SDK: This optional SDK becomes necessary if you intend to use the Adapty Paywall builder. The Paywall builder serves as a convenient, user-friendly tool tailored for a no-code approach. It empowers you with the ability to effortlessly construct a subscription purchase page, referred to as a Paywall in Adapty. This approach ensures you get the paywalls directly in your iOS or Android apps as native layout pages.
    The Adapty Paywall builder is created to set the core conversion-driving elements of paywalls with several clicks in the dashboard without spending time on minor design amendments and technical settings. It helps also to edit your paywall native layout on the fly by changing it visually in the Adapty web interface.

Please consult the compatibility table below to choose the correct pair of Adapty SDK and AdaptyUI SDK.

Adapty SDK versionAdaptyUI SDK version
2.7.x, 2.8.x2.0.x
2.9.x - 2.10.02.1.2
2.10.12.1.3
2.10.22.1.4
2.10.32.1.5

You can install AdaptySDK and AdaptyUI SDK via CocoaPods, or Swift Package Manager.

❗️

Go through release checklist before releasing your app

Before releasing your application, make sure to carefully review the Release Checklist thoroughly. This checklist ensures that you've completed all necessary steps and provides criteria for evaluating the success of your integration.

Install SDKs via CocoaPods

  1. Add Adapty to your Podfile:

    pod 'Adapty', '~> 2.10.3'
    pod 'AdaptyUI', '~> 2.1.5'
    
  2. Run:

    pod install
    

This creates a .xcworkspace file for your app. Use this file for all future development of your application.

Install SDKs via Swift Package Manager

  1. In Xcode go to File -> Swift Packages -> Add Package Dependency...
  2. Enter the repository URL https://github.com/adaptyteam/AdaptySDK-iOS.git
  3. Choose the version, and click the Add package button. Xcode will add the package dependency to your project, and you can import it.
  4. In the Choose Package Products window, click the Add package button once again. The package will appear in the Packages list.
  5. Repeat steps 2-3 for AdaptyUI SDK URL: https://github.com/adaptyteam/AdaptyUI-iOS.git.

Configure Adapty SDK

You only need to configure the Adapty SDK once, typically early in your application lifecycle:

// In your AppDelegate class:
import Adapty

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

    Adapty.activate("PUBLIC_SDK_KEY", customerUserId: "YOUR_USER_ID")
}
import Adapty

@main
struct SampleApp: App {
    init() 
        Adapty.activate("PUBLIC_SDK_KEY", customerUserId: "YOUR_USER_ID")
    }

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

Parameters:

ParameterPresenceDescription
PUBLIC_SDK_KEYrequiredThe key you can find in the Public SDK key field of your app settings in Adapty: App settings-> General tab -> API keys subsection
observerModeoptionalA boolean value controlling Observer mode. Turn it on if you handle purchases and subscription status yourself and use Adapty for sending subscription events and analytics.
The default value is false.

🚧 When running in Observer mode, Adapty SDK won't close any transactions, so make sure you're handling it.
customerUserIdoptionalAn identifier of the user in your system. We send it in subscription and analytical events, to attribute events to the right profile. You can also find customers by customerUserId in the Profiles and Segments menu.

📘

  • Note, that StoreKit 2 is available since iOS 15.0. Adapty will implement the legacy logic for older versions.
  • Make sure you use the Public SDK key for Adapty initialization, the Secret key should be used for server-side API only.
  • SDK keys are unique for every app, so if you have multiple apps make sure you choose the right one.

Set up the logging system

Adapty logs errors and other crucial information to provide insight into your app's functionality. There are the following available levels:

LevelDescription
errorOnly errors will be logged.
warnErrors and messages from the SDK that do not cause critical errors, but are worth paying attention to will be logged.
infoErrors, warnings, and serious information messages, such as those that log the lifecycle of various modules will be logged.
verboseAny additional information that may be useful during debugging, such as function calls, API queries, etc. will be logged.

You can set logLevel at any time in the application's lifespan, but we recommend that you do this before configuring Adapty.

Adapty.logLevel = .verbose

Redirect the logging system messages

If you for some reason need to send messages from Adapty to your system or save them to a file, you can override the default behavior:

Adapty.setLogHandler { level, message in
    writeToLocalFile("Adapty \(level): \(message)")
}

Disable data collection and sharing

You can disable IDFA collection and the user IP address sharing. By default, both IDFA and IP address are collected.

Adapty.idfaCollectionDisabled = true
Adapty.ipAddressCollectionDisabled = true

For more details on IDFA collection, refer to the Analytics integration section.