MoEngageInAppState

@objcMembers
public class MoEngageInAppState : MoEngageModelObject, NSCoding, Codable

A class that tracks the state and interaction history of an in-app campaign.

This class maintains important information about how an in-app campaign has been displayed and interacted with, including display counts, timing information, and completion status. It helps manage campaign lifecycle and prevents over-display of campaigns. It conforms to MoEngageModelObject, NSCoding, and Codable protocols for data persistence and management.

Properties

  • Unique identifier for the campaign this state belongs to.

    Declaration

    Swift

    public let campaignId: String
  • Timestamp when the campaign expires and should no longer be displayed. Made optional until the code is completely converted to swift

    Declaration

    Swift

    public var expiryTime: Date?
  • Timestamp for deletion based on the last synchronization with the server. This helps manage campaign cleanup and data consistency.

    Declaration

    Swift

    public var delTimeBasedOnLastSync: Date?
  • Timestamp when the campaign was last shown to the user. Defaults to epoch time (January 1, 1970).

    Declaration

    Swift

    public var lastShownTime: Date?
  • Total number of times this campaign has been displayed to the user. Used for frequency capping and analytics tracking.

    Declaration

    Swift

    public var numberOfTimesShown: Int
  • Flag indicating whether the user has completed the primary action associated with this campaign (e.g., clicked a button, completed a form).

    Declaration

    Swift

    public var primaryActionCompleted: Bool

init method

  • Initializes a new in-app state instance with campaign information.

    Declaration

    Swift

    @objc
    public convenience init(with campaignId: String, expiryTime: Date)

    Parameters

    campaignId

    Unique identifier for the campaign

    expiryTime

    Timestamp when the campaign expires

    deleteBasedOnLastSync

    Timestamp for deletion based on last sync

NSCoding

  • Initializes the in-app state from an NSCoder for unarchiving.

    Declaration

    Swift

    public required init?(coder decoder: NSCoder)

    Parameters

    decoder

    The coder to use for unarchiving.

    Return Value

    An initialized in-app state instance.

  • Encodes the in-app state using NSCoder for archiving.

    Declaration

    Swift

    public func encode(with encoder: NSCoder)

    Parameters

    encoder

    The coder to use for archiving.

Codable

  • Encodes the in-app state to an encoder.

    Throws

    Encoding errors if the data cannot be encoded.

    Declaration

    Swift

    public func encode(to encoder: any Encoder) throws

    Parameters

    encoder

    The encoder to write data to.

  • Initializes the in-app state from a decoder.

    Throws

    Decoding errors if the data is malformed.

    Declaration

    Swift

    public required init(from decoder: any Decoder) throws

    Parameters

    decoder

    The decoder to read data from.

  • Declaration

    Swift

    public func updateExpiryAndDeletionTime(expiryTime: Date)