MoEngageSDKInstanceProvider

public extension MoEngageSDKInstanceProvider
  • Returns MoEngageSDKInstance based on the target

    Declaration

    Swift

    @preconcurrency
    @MoEngageGlobalActor
    static func getSDKInstance(workspaceId: String? = nil) -> MoEngageSDKInstance?

    Parameters

    workspaceId

    MoEngage Account Identifier

    Return Value

    MoEngageSDKInstance belonging to the given account identifier

Initialization State Tracking

  • Runs the “SDK must be initialized” guard for the given workspace on the current tracker.

    The default tracker calls fatalError when the guard fires (see InitializationTracker/preconditionSDKInitialized(for:)).

    In test bundles, MoEngageTestConfigurator (via ObjC +load in MoEngageTestSupport) calls disablePreconditionSDKInitialized() at dylib load time — before any test framework starts — so the default tracker never crashes the process during testing.

    Tests that need to assert the guard fires (e.g. MoEngageActionCrashGuardTests) bind their own capturing tracker for the duration of the call:

    await MoEngageSDKInstanceProvider.$initializationTracker.withValue(
        .init { workspaceId in captured = workspaceId }
    ) { /* trigger the guarded API */ }
    

    Declaration

    Swift

    public static func preconditionSDKInitialized(_ workspaceId: String?)
  • Neutralises the default tracker’s missing-workspace action process-wide by mutating it in place. Called by MoEngageTestConfigurator at dylib load time in test bundles.

    Declaration

    Swift

    @objc
    public static func disablePreconditionSDKInitialized()
  • Declaration

    Swift

    public func markInitializationRequested(for workspaceId: String, isDefault: Bool)
  • Returns all registered SDK instances as an array.

    Note

    Use fetchInstances() instead, which returns the instances keyed by workspace ID. Iterate its values where an array of instances is required.

    Declaration

    Swift

    @available(*, deprecated, message: "Use `fetchInstances(﹚` instead.")
    @preconcurrency
    @MoEngageGlobalActor
    public func fetchInstanceCache() -> [MoEngageSDKInstance]