Event

enum Event : Hashable, @unchecked Sendable

Synchronous lifecycle events that modules can respond to.

These events represent key points in a module’s lifecycle or significant SDK state transitions. Events are delivered via Item.process(event:sdkInstance:), which runs on the MoEngageSDKInstance actor’s executor.

Core Lifecycle Order

For a typical app session:

  1. .init — called once when module is registered
  2. .start — called after all modules are initialized
  3. .deinit — called when SDK instance is being removed (rare)
  • Module initialization event.

    Called when the module is first registered with the SDK instance. This is the appropriate time to:

    • Register notification observers
    • Set up KVO observations
    • Subscribe to system events
    • Register delegates/callbacks with other modules

    Restrictions

    During init, modules should NOT:

    • Mutate state that other modules might observe
    • Make network requests
    • Access disk (except for critical configuration)
    • Perform expensive operations

    Rationale

    At this stage, other modules may not be fully initialized. Mutating shared state could cause race conditions or trigger observers before the observing module is ready.

    Declaration

    Swift

    case `init`
  • Module start event.

    Called after all modules have completed their init phase. This is the appropriate time to:

    • Update initial state (track app opened, reinstall detection)
    • Process queued events
    • Make initial network requests
    • Begin active processing

    Rationale

    All modules are now initialized and ready to respond to changes. This is the “app is ready” signal for modules to begin their work.

    Declaration

    Swift

    case start
  • Module deinitialization event.

    Called when the SDK instance is being removed or deallocated. This is the appropriate time to:

    • Remove notification observers
    • Cancel ongoing operations
    • Clean up resources
    • Unregister delegates/callbacks

    Use Cases

    This event is called when:

    • The default workspace ID changes and the old instance is being removed
    • The app explicitly resets the SDK
    • (Rare) The SDK is being completely unloaded

    Note

    This is rarely called in normal app operation. Most apps will have a single SDK instance for the app’s lifetime.

    Declaration

    Swift

    case `deinit`

Session

  • A new SDK session was created.

    Declaration

    Swift

    case didCreateSession

Data tracking

  • A batch of view-tracking info was recorded.

    Declaration

    Swift

    case didTrackInfo(_: TrackInfo)

    Parameters

    info

    The tracked views payload.

Identity

  • The user unique ID changed.

    Declaration

    Swift

    case didUpdateUid(_: String?, _: String)

    Parameters

    fromUid

    The previous UID.

    toUid

    The new UID.

  • The user identities dictionary changed.

    Declaration

    Swift

    case didUpdateIdentities(_: [String : String], _: [String : String])

    Parameters

    fromIdentities

    The previous identities.

    toIdentities

    The new identities.

SDK state

  • The SDK enabled/disabled state changed.

    Declaration

    Swift

    case didUpdateSDKState(_: Bool)

    Parameters

    enabled

    true if the SDK is now enabled.

  • The user’s opt-in status for data tracking changed.

    Declaration

    Swift

    case didUpdateOptInForDataTracking(_: Bool)

    Parameters

    status

    true if the user opted in.

  • The SDK environment (e.g. data centre region) was updated.

    Declaration

    Swift

    case didUpdateConfig(
        _ fromConfig: MoEngageConfig.Data,
        _ toConfig: MoEngageConfig.Data,
        isSourceInitialization: Bool
    )

    Parameters

    fromConfig

    The configuration before the update.

    toConfig

    The configuration after the update.

    isSourceInitialization

    true when the change is applied while loading persisted config during SDK source initialization (.init); false for a runtime config update via the public API.

  • A remote config sync completed.

    Declaration

    Swift

    case didUpdateRemoteConfig(
        _ fromConfig: MoEngageConfig.Remote.Data, _ toConfig: MoEngageConfig.Remote.Data
    )

Auth

  • The user logged out successfully.

    Declaration

    Swift

    case didLogout
  • The SDK was unregistered for this instance.

    Declaration

    Swift

    case didUnregister

App & system

Event.TrackInfo

Event.AppLifecycleEvent

  • Wraps a foreground-entry app lifecycle notification.

    See more

    Declaration

    Swift

    struct AppLifecycleEvent : Hashable, @unchecked Sendable

Event.PushNotificationEvent

  • Wraps a push-notification related event.

    See more

    Declaration

    Swift

    enum PushNotificationEvent : Hashable, @unchecked Sendable