Configuration

After installing the SDK, you can configure the MagifyClient instance to match your application environment and runtime behavior.

The SDK provides several configuration options for:

  • environment management;
  • client identity;
  • logging;
  • GeoIP support;
  • subscription synchronization;
  • attribution SDK integration.

Initializing 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 strongly recommend using a single shared client instance for your application.

This uniqueness is important to avoid conflicts or unexpected behavior when multiple instances might otherwise be created.


Application name

The for: parameter specifies the application identifier registered in the Magify Dashboard.

for: "MyApplication"

This value should match the application name configured for your project.


Configuration file

The defaultConfigURL parameter points to the local Magify-Config.json file bundled with your application.

defaultConfigURL: configURL

The configuration file may contain:

  • limits;
  • campaigns;
  • features;
  • content configuration;
  • native elements.

The file must be included in your application target before SDK initialization.


Sandbox environment

The SDK supports separate sandbox and production environments.

Use the isSandbox parameter to specify the current environment.

isSandbox: true

Use sandbox mode only for testing environments.

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


Set user context (Optional)

The SDK allows you to configure optional user and runtime context before calling:

magify.setup()

Providing attribution and privacy-related information before SDK initialization helps improve campaign targeting and runtime synchronization.

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
        )

        // Optional flags.
        magify.isGeoIPEnabled = true
        magify.isLoggingEnabled = true

        // Observe subscription state changes.
        magify.onSubscriptionStatusChanged = {
            // TODO: Handle subscription changed state.
        }

        return magify
    }()

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

        // Sync third-party SDKs with Magify client ID.
        AppsFlyerLib.shared().customerUserID = magify.clientId

        magify.setup()

        return true
    }
}

The SDK should be fully configured before calling setup() whenever possible.


Logging

Logging can be enabled to help debug SDK integration and runtime behavior.

magify.isLoggingEnabled = true

When enabled, SDK activity can be monitored through the Xcode console.

We recommend enabling logging during development and disabling it in production builds unless additional diagnostics are required.


GeoIP support

The SDK optionally supports GeoIP-based functionality.

Enable GeoIP support by setting:

magify.isGeoIPEnabled = true

GeoIP functionality may be used by backend services to improve content delivery and runtime targeting.


Client identity

Each SDK client is associated with a clientId.

The identifier can either:

  • be generated automatically by the SDK;
  • or be provided manually during initialization.

Example:

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

Automatic clientId generation

If no clientId value is provided, the SDK automatically generates a unique identifier.

The generated identifier:

  • remains stable between application launches;
  • is unique per environment;
  • is reused until a custom identifier is specified.

Sandbox and production environments use different automatically generated identifiers.


Immutable client identity

The clientId value cannot be changed after the MagifyClient instance is created.

To switch users, create a new client instance with another identifier.

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

Subscription status synchronization

The SDK allows applications to synchronize subscription state manually.

magify.subscriptionStatus = .active(isTrial: false)

Applications should update the subscription status after successful purchases or subscription state changes.


Next step

Now that the SDK is configured, you can proceed to the SDK Lifecycle section to learn how the SDK behaves during application runtime and foreground synchronization.

Related articles

ImageCreative

Analytics Service

Aghanim purchases

CrossPromoProduct

Features Provider

CampaignsProvider