MoEngageInAppController

extension MoEngageInAppController
extension MoEngageInAppController: MoEngageTestInAppProtocol

Global Delay Check

  • Check if global delay between InApps has been satisfied

    Declaration

    Swift

    @objc
    public func checkGlobalDelayForInApps() -> Bool

    Return Value

    true if global delay check passed, false otherwise

Campaign Expiry Check

  • Check if campaign has expired

    Declaration

    Swift

    @objc
    public func checkCampaignExpiry(for campaign: MoEngageInAppCampaignMeta) -> Bool

    Parameters

    campaign

    The campaign to check

    Return Value

    true if campaign is not expired, false if expired

Context Check

  • Check if campaign contexts match current app contexts

    Declaration

    Swift

    @objc
    public func checkContexts(for campaign: MoEngageInAppCampaignMeta) -> Bool

    Parameters

    campaign

    The campaign to check

    Return Value

    true if context check passed, false otherwise

Screen Check

  • Check if campaign should be shown on current screen

    Declaration

    Swift

    @objc
    public func checkShowInScreen(for campaign: MoEngageInAppCampaignMeta) -> Bool

    Parameters

    campaign

    The campaign to check

    Return Value

    true if screen check passed, false otherwise

Orientation Check

  • Check if current device orientation is supported by the campaign

    Declaration

    Swift

    @objc
    public func checkIfCurrentOrientationIsSupported(_ campaignOrientationType: MoEngageInAppOrientationType) -> Bool

    Parameters

    campaignOrientationType

    The orientation type supported by the campaign

    Return Value

    true if orientation is supported, false otherwise

State Instance Check

  • Check campaign state instance for persistence, max times shown, and campaign-level delay. Validates campaign against stored state to determine if it can be shown again.

    Declaration

    Swift

    @objc
    public func checkWithStateInstance(for campaign: MoEngageInAppCampaignMeta, isPrioratizingStage: Bool) -> Bool

    Parameters

    campaign

    The campaign to check

    isPrioratizingStage

    Whether this is the priority stage (affects stat tracking)

    Return Value

    true if all state checks pass and campaign can be shown, false otherwise

InApp Enabled Check

  • Check if InApp is enabled (SDK enabled, not disabled by developer, config API enabled, user registered)

    Declaration

    Swift

    @objc
    public func isInAppEnabled() -> Bool

    Return Value

    true if InApp is enabled, false otherwise

Should Show InApp Check

  • Check if InApp should be shown (enabled and sync completed)

    Declaration

    Swift

    @objc
    public func shouldShowInApp() -> Bool

    Return Value

    true if InApp should be shown, false otherwise

Pre-conditions Check

  • Check pre-conditions for showing InApps (screen blocking)

    Declaration

    Swift

    @objc
    public func checkPreConditions(
        for campaigns: [MoEngageInAppCampaignMeta],
        withType sdkCmpType: MoEngageInAppSDKCampaignType,
        isPrioratizingStage: Bool
    ) -> Bool

    Parameters

    campaigns

    Array of campaigns to check

    sdkCmpType

    The SDK campaign type

    isPrioratizingStage

    Whether this is the priority stage

    Return Value

    true if pre-conditions are satisfied, false otherwise

Composite Rule Check (without explicit trigger type)

  • Check if all rules are satisfied for an InApp campaign. Performs FC check followed by non-FC rules (nudge, push opt-in, delay, expiry, screen, context, orientation, state).

    Declaration

    Swift

    @objc
    public func checkIfRulesSatisfied(
        for campaign: MoEngageInAppCampaignMeta,
        inPrioratizingStage isPrioratizingStage: Bool
    ) -> Bool

    Parameters

    campaign

    The campaign to check

    isPrioratizingStage

    Whether this is the priority stage (affects stat tracking)

    Return Value

    true if all rules pass and campaign is eligible to show, false otherwise

Composite Rule Check (with explicit trigger type)

  • Check if all rules are satisfied for an InApp campaign with explicit trigger type. Performs FC check with specified trigger type followed by non-FC rules.

    Declaration

    Swift

    @objc
    public func checkIfRulesSatisfied(
        for campaign: MoEngageInAppCampaignMeta,
        triggerType: Int,
        inPrioratizingStage isPrioratizingStage: Bool
    ) -> Bool

    Parameters

    campaign

    The campaign to check

    triggerType

    The explicit trigger type for FC evaluation

    isPrioratizingStage

    Whether this is the priority stage (affects stat tracking)

    Return Value

    true if all rules pass and campaign is eligible to show, false otherwise

Get Eligible Campaign (Multiple Context)

  • Get eligible campaigns for multiple context validation

    Declaration

    Swift

    @objc
    public func getEligibleCampaignForMultipleContext(
        _ campaignsArray: [MoEngageInAppCampaignMeta],
        forSDKCampaignType sdkCmpType: MoEngageInAppSDKCampaignType,
        inPrioratizingStage inPrioratizing: Bool
    ) -> [MoEngageInAppCampaignMeta]

    Parameters

    campaignsArray

    Array of campaigns to evaluate

    sdkCmpType

    The SDK campaign type

    inPrioratizing

    Whether this is the priority stage

    Return Value

    Array of eligible campaigns

Get Eligible Campaign (Single - Default)

  • Get the most eligible campaign using default validation

    Declaration

    Swift

    @objc
    public func getEligibleCampaign(
        _ campaignsArray: [MoEngageInAppCampaignMeta],
        forSDKCampaignType sdkCmpType: MoEngageInAppSDKCampaignType,
        inPrioratizingStage inPrioratizing: Bool
    ) -> MoEngageInAppCampaignMeta?

    Parameters

    campaignsArray

    Array of campaigns to evaluate

    sdkCmpType

    The SDK campaign type

    inPrioratizing

    Whether this is the priority stage

    Return Value

    The most eligible campaign, or nil if none found

Get Eligible Campaign (Core Implementation)

  • Core implementation for getting eligible campaigns with validation type. Performs precondition checks followed by rule evaluation for each campaign.

    Declaration

    Swift

    @objc
    public func getEligibleCampaign(
        _ campaignsArray: [MoEngageInAppCampaignMeta],
        forSDKCampaignType sdkCmpType: MoEngageInAppSDKCampaignType,
        inPrioratizingStage inPrioratizing: Bool,
        validationType type: MoEngageInAppEligibleCriteria
    ) -> [MoEngageInAppCampaignMeta]

    Parameters

    campaignsArray

    Array of campaigns to evaluate (must be non-empty)

    sdkCmpType

    The SDK campaign type for logging

    inPrioratizing

    Whether this is the priority stage (affects stat tracking)

    type

    The validation type - .multipleContext returns all eligible, .defaultValidation returns first match

    Return Value

    Array of eligible campaigns (empty if none qualify or preconditions fail)

Confirmance to test inapp protocol

Segment Re-Evaluation Methods

  • Check if segment re-evaluation meta sync should be performed based on 3-minute interval

    Declaration

    Swift

    func shouldPerformSegmentReevalMetaSync() -> Bool

    Return Value

    true if sync should be performed (first sync or > 3 minutes since last sync), false otherwise

  • Handle segment re-evaluation failure when backend returns 412 error with E002 code This method is called from Objective-C which has already validated the 412/E002 error

    Declaration

    Swift

    func handleSegmentReevalFailure(
        campaignMeta: MoEngageInAppCampaignMeta,
        responseData: [AnyHashable: Any]?
    )

    Parameters

    campaignMeta

    The campaign metadata that failed segment re-evaluation

    responseData

    The parsed error response dictionary from the server

Nudge UI Logic

  • Calculate the frame for a HTML nudge based on its payload and position

    Declaration

    Swift

    @objc
    public static func calculateNudgeFrame(_ payload: MoEngageInAppViewPayload) -> CGRect

    Parameters

    payload

    The InApp view payload containing style and position information

    Return Value

    The calculated CGRect for the nudge

Session Management

  • Sync session and clear counters if session changed (called from Objective-C)

    Declaration

    Swift

    @objc
    public func syncAndClearSessionCountersIfNeeded()
  • Call this from application lifecycle events

    Declaration

    Swift

    @objc
    public func syncFCSessionOnAppForeground()
  • Call this from application lifecycle events Per technical doc: “On App background - Trigger sync if any data sync is pending”

    Declaration

    Swift

    @objc
    public func triggerFCsyncOnAppBackground()

FC Evaluation Methods

  • Check FC rules for a campaign (main entry point called from Objective-C)

    Declaration

    Swift

    @objc
    public func checkFCRulesForCampaign(_ campaign: MoEngageInAppCampaignMeta, isPrioratizingStage: Bool) -> Bool

    Parameters

    campaign

    The campaign to check

    isPrioratizingStage

    Whether this is in prioritizing stage

    Return Value

    True if FC rules allow the campaign, false otherwise

  • Check FC rules for a campaign with explicit trigger type (called from Objective-C)

    Declaration

    Swift

    @objc
    public func checkFCRulesForCampaign(_ campaign: MoEngageInAppCampaignMeta, triggerType: NSInteger, isPrioratizingStage: Bool) -> Bool

    Parameters

    campaign

    The campaign to check

    triggerType

    The explicit trigger type as NSInteger (for Objective-C compatibility)

    isPrioratizingStage

    Whether this is in prioritizing stage

    Return Value

    True if FC rules allow the campaign, false otherwise

  • Re-evaluate FC for impression tracking (called from Objective-C)

    Declaration

    Swift

    @objc
    public func reEvaluateFCForImpressionWithCampaign(_ campaign: MoEngageInAppCampaign) -> Bool

    Parameters

    campaign

    The campaign to re-evaluate

    Return Value

    True if FC rules still allow the campaign, false otherwise

FC Counter Management & Ingestion

  • Increment FC counters after campaign is shown (called from Objective-C)

    Declaration

    Swift

    @objc
    public func incrementFCCountersForCampaign(_ campaign: MoEngageInAppCampaign)
  • Processes frequency data from template payload and ingests it into FC state manager.

    Declaration

    Swift

    @objc
    public func processFrequencyDataFromPayload(_ payload: MoEngageInAppViewPayload)

    Parameters

    payload

    The view payload containing frequency data