SwiftUI

Learn how to use Adapty iOS SDK in SwiftUI applications

SwiftUI App Lifecycle

Since Xcode 12 and the new SwiftUI, the app can be created without AppDelegate at all.
You can put your configuration code inside init method.

import Adapty

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

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

Or you can still do it through AppDelegate, but it requires you to create your own @UIApplicationDelegateAdaptor.

import Adapty

@main
struct SwiftUISampleApp: App {
    @UIApplicationDelegateAdaptor private var appDelegate: AppDelegate
    
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}

class AppDelegate: UIResponder, UIApplicationDelegate {
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
        Adapty.activate("PUBLIC_SDK_KEY", customerUserId: "YOUR_USER_ID")
        return true
    }
}

Did this page help you?