UIApplication

extension UIApplication: MoEngageUIApplication

Extension making UIApplication conform to MoEngageUIApplication.

This extension enables the real UIApplication to be used interchangeably with mock implementations through the protocol abstraction.

  • Implements delegate change observation for UIApplication.

    This method wraps the standard KVO API to provide a simpler interface for observing delegate changes.

    Declaration

    Swift

    @MainActor
    public func observeDelegateChanges(
        changeHandler: @escaping @Sendable (
            _ oldDelegate: UIApplicationDelegate?,
            _ newDelegate: UIApplicationDelegate?
        ) -> Void
    ) -> NSKeyValueObservation

    Parameters

    changeHandler

    Called when the delegate property changes.

    Return Value

    The KVO observation object.

  • Witness for MoEngageUIApplication/beginMoEngageBackgroundTask(withName:expirationHandler:) that forwards to UIApplication‘s native beginBackgroundTask(withName:expirationHandler:).

    The native expiration handler is non-isolated, so the @Sendable @MainActor handler is dispatched through MoEngageObjectiveCRuntime.executeOnMain to guarantee it runs on the main actor. beginBackgroundTask itself is safe to call from any thread, so this witness can stay nonisolated and be invoked synchronously from the SDK’s actors.

    Declaration

    Swift

    public nonisolated func beginMoEngageBackgroundTask(
        withName taskName: String?, expirationHandler handler: (@Sendable @MainActor () -> Void)?
    ) -> UIBackgroundTaskIdentifier

    Parameters

    taskName

    A descriptive name for the task, used only for debugging.

    handler

    The expiration handler, invoked on the main actor before background time expires.

    Return Value

    The background task token, or UIBackgroundTaskIdentifier.invalid if the request failed.