SDK Initialization

Creating MagifyClient

MagifyClient is the main SDK entry point.

Usually, the client is created during application startup and reused throughout the entire application lifecycle.

import UIKit
import Magify

@main
class AppDelegate: UIResponder, UIApplicationDelegate {

    lazy var magify: MagifyClient = {
        let configURL = Bundle.main.url(
            forResource: "Magify-Config",
            withExtension: "json"
        )!

        let magify = MagifyClient(
            for: "MyApplication",
            defaultConfigURL: configURL,
            isSandbox: false
        )

        return magify
    }()
}

We recommend using a single shared client instance throughout the application lifecycle.

Sandbox and production environments

The SDK supports separate sandbox and production environments.

Use the isSandbox parameter to specify the current environment.

let magify = MagifyClient(
    for: "MyApplication",
    defaultConfigURL: configURL,
    isSandbox: true
)

Use sandbox mode only for testing environments.

The SDK maintains separate client identities for sandbox and production environments.

Set user context (Optional)

Provide attribution and privacy-related information before calling setup() for the most accurate campaign targeting and runtime synchronization.

Example:

AppsFlyerLib.shared().customerUserID = magify.clientId

Whenever possible, complete SDK configuration before calling:

magify.setup()

Initializing SDK with other libraries

The SDK can be integrated with third-party attribution providers such as AppsFlyer.

AppsFlyer clientId is passed to Magify as clientId

let clientId = AppsFlyerLib.shared().getAppsFlyerUID()

magify = MagifyClient(
    for: "Example iOS",
    defaultConfigURL: configURL,
    isSandbox: isSandbox,
    clientId: clientId,
    receiptObservationEnabled: false
)

If Magify is initialized first

let clientId = "User Client Id"

let magify = MagifyClient(
    for: Settings.isStableConfig ? "Example iOS Stable" : "Example iOS",
    defaultConfigURL: URL(
        fileURLWithPath: Bundle.main.path(
            forResource: "Magify-Config.json",
            ofType: nil
        )!
    ),
    isSandbox: isSandbox,
    clientId: clientId,
    receiptObservationEnabled: false
)

AppsFlyerLib.shared().customerUserID = clientId

// AppsFlyer initialization
// ...

SDKs are initialized only after authorization

let clientId = "User Client Id" // Configure Client Id

AppsFlyerLib.shared().customerUserID = clientId

// AppsFlyer initialization
// ...

let magify = MagifyClient(
    for: Settings.isStableConfig ? "Example iOS Stable" : "Example iOS",
    defaultConfigURL: URL(
        fileURLWithPath: Bundle.main.path(
            forResource: "Magify-Config.json",
            ofType: nil
        )!
    ),
    isSandbox: isSandbox,
    clientId: clientId,
    receiptObservationEnabled: false
)

Use clientId for all integrations

After the client is set up, propagate magify.clientId to every connected third-party SDK so attribution and analytics share the same user identifier.

For AppsFlyer, Adjust, AppLovin MAX, LevelPlay/IronSource, and RevenueCat, see Integration with other SDK.

Next step

Continue with Configuration options to set optional runtime flags, manage client identity, and synchronize subscription status.

Related articles

Advertisement

Service Time

PurchaseInfo

ContentItem

Campaigns

IPopupsProvider