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:
.init— called once when module is registered.start— called after all modules are initialized.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
initphase. 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`
-
A new SDK session was created.
Declaration
Swift
case didCreateSession
-
A batch of view-tracking info was recorded.
Declaration
Swift
case didTrackInfo(_: TrackInfo)Parameters
infoThe tracked views payload.
-
The user unique ID changed.
Declaration
Swift
case didUpdateUid(_: String?, _: String)Parameters
fromUidThe previous UID.
toUidThe new UID.
-
The user identities dictionary changed.
Declaration
Swift
case didUpdateIdentities(_: [String : String], _: [String : String])Parameters
fromIdentitiesThe previous identities.
toIdentitiesThe new identities.
-
The SDK enabled/disabled state changed.
Declaration
Swift
case didUpdateSDKState(_: Bool)Parameters
enabledtrueif the SDK is now enabled. -
The user’s opt-in status for data tracking changed.
Declaration
Swift
case didUpdateOptInForDataTracking(_: Bool)Parameters
statustrueif 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
fromConfigThe configuration before the update.
toConfigThe configuration after the update.
isSourceInitializationtruewhen the change is applied while loading persisted config during SDK source initialization (.init);falsefor 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 )
-
The user logged out successfully.
Declaration
Swift
case didLogout -
The SDK was unregistered for this instance.
Declaration
Swift
case didUnregister
-
An app lifecycle event was received.
Declaration
Swift
case didRecieveFromAppLifecycle(_: AppLifecycleEvent)Parameters
eventThe wrapped lifecycle notification and its type.
-
A URL was opened by the app.
Declaration
Swift
case didOpen(_: URL)Parameters
urlThe opened URL.
-
A push notification event was received.
Declaration
Swift
case didRecievePushNotification(_: PushNotificationEvent)Parameters
eventThe specific push event (token update, presentation, or response).
-
A raw
Notificationwas received from the system or another module. Modules opt in to specific names viaItem.listensToAdditionalNotifications().Declaration
Swift
case didRecieveFromSystem(_: Notification)Parameters
notificationThe received notification.
-
Public representation of a tracked-views batch payload delivered via
See moredidTrackInfo(_:).Declaration
Swift
struct TrackInfo : Hashable, Sendable
-
Wraps a foreground-entry app lifecycle notification.
See moreDeclaration
Swift
struct AppLifecycleEvent : Hashable, @unchecked Sendable
-
Wraps a push-notification related event.
See moreDeclaration
Swift
enum PushNotificationEvent : Hashable, @unchecked Sendable