Introduction

The Magify Swift SDK enables you to integrate analytics, purchases tracking, campaign delivery, remote configuration, and content management into your iOS application.

The SDK is designed to provide a lightweight and native integration experience for Swift-based applications while remaining flexible enough for custom runtime behavior and advanced application architectures.


Before you begin

Before integrating the SDK, make sure your project meets the following requirements:

  • iOS 15.0 or later
  • Xcode 15 or later
  • Swift 5.9 or later

You will also need access to the Magify Dashboard in order to download your application configuration file.


Architecture overview

The main entry point of the SDK is the MagifyClient object.

MagifyClient is responsible for:

  • loading SDK configuration;
  • managing client identity;
  • synchronizing application state;
  • tracking subscriptions and purchases;
  • updating runtime content and features;
  • communicating with Magify backend services.

The SDK is designed around a single shared client instance that lives throughout the application lifecycle.


We recommend creating and managing a single shared MagifyClient instance during application startup.

Usually, the SDK is initialized inside the application delegate:

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
    }()

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

        magify.setup()

        return true
    }
}

This approach ensures that the SDK remains synchronized with the application lifecycle and avoids conflicts caused by creating multiple client instances.


Application lifecycle

The SDK should be initialized once during application launch by calling:

magify.setup()

After initialization, the SDK should be updated whenever the application becomes active:

magify.update()

For UIKit lifecycle integrations, this is commonly handled inside:

sceneDidBecomeActive(_:)

This allows the SDK to refresh runtime state, synchronize campaigns and features, and update client-related information whenever the application returns to the foreground.


Configuration file

The SDK requires a Magify-Config.json configuration file generated in the Magify Dashboard.

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 and production environments

The SDK supports separate sandbox and production environments through the isSandbox parameter.

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.


Client identity

Each MagifyClient instance is associated with a clientId.

If no custom 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 provided.

The clientId value is immutable after the client instance is created.

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


Optional SDK features

The SDK also provides optional runtime features, including:

  • logging;
  • GeoIP support;
  • subscription status synchronization;
  • attribution SDK synchronization.

Next step

Now that you understand the SDK architecture and lifecycle, you can proceed to the Installation section to add the Magify Swift SDK to your project.

Related articles

BonusProduct

UnityPurchasing

AghanimProductCounting

TrustedPurchaseRecord

MagifyPresenter

MagifyConfig