Initialize Setapp Framework

Once you've added the public key(s), you should tell our Setapp Framework its location. By default, we assume that there is only one public key file named setappPublicKey.pem, and located in the app's main bundle.

Start

The start(with:) or start(with:setappMobileConfiguration:) methods of SetappManager class are responsible for these initialization operations:

  • Providing configuration for the Setapp Framework so that it starts for your app.
  • Start reporting the app usage once it is successfully activated for a Setapp user.

🚧

Important

You must call one of these methods before calling any other SetappManager.shared instance methods.

If you have the UIApplicationDelegate method in your app, add the following code to the application(_:, didFinishLaunchingWithOptions:) function:

import Setapp

class AppDelegate: UIResponder, UIApplicationDelegate {
  
  func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) 
  -> Bool
  {
    SetappManager.shared.start(with: .default)
    return true
  }

}

If you have UIWindowSceneDelegate in your app, add the code below to the scene(_:, willConnectTo:, options:) function:

import Setapp

class SceneDelegate: UIResponder, UIWindowSceneDelegate {
  
  func scene(
    _ scene: UIScene,
    willConnectTo session: UISceneSession,
    options connectionOptions: UIScene.ConnectionOptions
  )
  {
    SetappManager.shared.start(with: .default)
  }

}

If your app has a SwiftUI app lifecycle, add the following code below to your App object's init() method:

import SwiftUI
import Setapp

@main
struct SampleApp: App {
    
    init() {        
        #if os(iOS)
        SetappManager.shared.start(with: .default)
        #endif
    }
  
}

Provide custom configuration

You’ll need to provide a custom configuration for the SetappManager class in the following cases:

  • You’re not using the main app bundle to store the public key.
  • You have renamed the public key file in your project.
  • You have multiple public key files in your project.

Configuration must be provided while initializing the Setapp Framework.

let configuration = SetappConfiguration(
  publicKeyBundle: .main,
  publicKeyFilename: "setappPublicKey.pem"
)

SetappManager.shared.start(with: configuration)

Support multiple app distributors

If you distribute your app via Setapp and Setapp Mobile, you'll need to specify a separate configuration for Setapp Mobile distribution using start(with:setappMobileConfiguration:) method:

let defaultConfiguration = SetappConfiguration(
	publicKeyBundle: .main,
	publicKeyFilename: "setappPublicKey.default.pem"
)
        
let setappMobileConfiguration = SetappConfiguration(
	publicKeyBundle: .main,
	publicKeyFilename: "setappPublicKey.setappMobile.pem"
)

SetappManager.shared.start(
	with: configuration,
	setappMobileConfiguration: setappMobileConfiguration
)