MoEngageSDKMessaging

@objc
public class MoEngageSDKMessaging : NSObject

Class responsible for Push integration

  • Singleton instance

    Declaration

    Swift

    @objc
    public static let sharedInstance: MoEngageSDKMessaging

Push Handlers

  • Requests the user’s authorization to allow local and remote notifications for your app.

    Declaration

    Swift

    @available(tvOS, unavailable)
    @available(iOSApplicationExtension, unavailable)
    @discardableResult
    @objc
    public func registerForRemoteNotification(
        withCategories categories: Set<UNNotificationCategory>? = nil,
        andUserNotificationCenterDelegate delegate: UNUserNotificationCenterDelegate? = nil
    ) -> MoEngagePushTokenTask

    Parameters

    categories

    A type of notification your app supports and the custom actions that the system displays.

    delegate

    The interface for handling incoming notifications and notification-related actions.

    Return Value

    MoEngagePushTokenTask resolving once the registration request has been issued to the OS. APNs-side success/failure (token delivery, permission grant) is delivered separately via MoEngageMessagingDelegate.

  • Method to register for provisional push permission.

    Declaration

    Swift

    @available(iOS 12.0, *)
    @available(tvOS, unavailable)
    @discardableResult
    @objc
    public func registerForRemoteProvisionalNotification(
        withCategories categories: Set<UNNotificationCategory>? = nil,
        andUserNotificationCenterDelegate delegate: UNUserNotificationCenterDelegate? = nil
    ) -> MoEngagePushTokenTask

    Parameters

    categories

    A type of notification your app supports and the custom actions that the system displays.

    delegate

    The interface for handling incoming notifications and notification-related actions.

    Return Value

    MoEngagePushTokenTask — same contract as registerForRemoteNotification(...).

  • Method to add the notification categories to the existing list of MOE_DISMISS_CATEGORY and MOE_PUSH_TEMPLATE category.

    Declaration

    Swift

    @available(tvOS, unavailable)
    @discardableResult
    @objc
    public func setUserNotificationCategories(_ categories: Set<UNNotificationCategory>? = nil) -> MoEngagePushTokenTask

    Parameters

    categories

    Set of categories.

    Return Value

    MoEngagePushTokenTask resolving once the categories have been registered with UNUserNotificationCenter.

Delegate setup

Push Callback methods

  • In case you have disabled swizzling, call this method to pass the device token to MoEngage SDK.

    Declaration

    Swift

    @available(iOSApplicationExtension, unavailable)
    @available(tvOS, unavailable)
    @discardableResult
    @objc
    public func setPushToken(_ deviceToken: Data?) -> MoEngagePushTokenTask

    Parameters

    deviceToken

    Identifier for the Apple Push Notification System.

    Return Value

    MoEngagePushTokenTask resolving once the token has been accepted into the SDK’s register pipeline. Rejects with .invalidPushToken when deviceToken is nil or empty.

  • In case you have disabled swizzling, call this method when notification registration fails.

    onSuccess fires once the SDK has accepted the register-failure signal — the task represents the outcome of this call, not the underlying APNs event. onFailure fires with .sdkNotInitialized if the SDK isn’t initialized yet.

    Declaration

    Swift

    @available(iOSApplicationExtension, unavailable)
    @available(tvOS, unavailable)
    @discardableResult
    @objc
    public func didFailToRegisterForPush() -> MoEngagePushTokenTask
  • In case you have disabled swizzling, call this method on receiving the notification.

    Stays Void — framework-callback forwarder (customer plumbing OS events into the SDK), not an action API. Same out-of-scope category as setMessagingDelegate.

    Declaration

    Swift

    @available(iOSApplicationExtension, unavailable)
    @available(tvOS, unavailable)
    @objc
    public func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification)

    Parameters

    center

    The central object for managing notification-related activities for your app or app extension.

    notification

    The data for a local or remote notification the system delivers to your app.

  • In case you have disabled swizzling, call this method on performing any action on the notification.

    Stays Void-returning: framework-callback forwarder (see userNotificationCenter(_:willPresent:)).

    Declaration

    Swift

    @available(iOSApplicationExtension, unavailable)
    @available(tvOS, unavailable)
    @objc
    public func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse)

    Parameters

    center

    The central object for managing notification-related activities for your app or app extension.

    response

    The user’s response to an actionable notification.

Badge reset

  • Method to disable badge reset by SDK

    Declaration

    Swift

    @available(tvOS, unavailable)
    @available(*, deprecated, message: "Use MoEngageBadgeUpdateEnabled key in Info.plist instead.")
    @objc
    public func disableBadgeReset(_ disable: Bool)

    Parameters

    disable

    Pass true to disable badge reset

Push Handled by Application

  • Track notification received impression.

    Declaration

    Swift

    @available(tvOS, unavailable)
    @discardableResult
    @objc
    public func logNotificationReceived(withPayload payload: [AnyHashable : Any]) -> MoEngageLogNotificationTask

    Parameters

    payload

    APNS notification payload.

    Return Value

    MoEngageLogNotificationTask resolving onSuccess after the impression is accepted into the local batch storage. Rejects with .duplicateImpression if the same impression payload was already tracked in a prior call (dedup), or with .sdkNotInitialized when no SDK instance matches the payload’s workspace.

  • Track notification received impression with a completion callback.

    Deprecated. Use the typed-task-returning logNotificationReceived(withPayload:) variant; attach onSuccess to be notified when the impression is logged.

    Declaration

    Swift

    @available(tvOS, unavailable)
    @available(*, deprecated, message: "Use the typed-task-returning logNotificationReceived(withPayload:﹚ variant; attach onSuccess to be notified when the impression is logged.")
    @objc
    public func logNotificationReceived(withPayload payload: [AnyHashable : Any], completion: @escaping () -> Void)

    Parameters

    payload

    APNS notification payload.

    completion

    Callback when notification received impression track completed.

  • Track notification click impression.

    Declaration

    Swift

    @available(iOSApplicationExtension, unavailable)
    @available(tvOS, unavailable)
    @discardableResult
    @objc
    public func logNotificationClicked(withPayload payload: [AnyHashable : Any]) -> MoEngageLogNotificationTask

    Parameters

    payload

    APNS notification payload.

    Return Value

    MoEngageLogNotificationTask resolving once the click has been logged. For non-MoEngage payloads the task resolves with the echoed payload after the session-source-update side-effect (no click impression is logged for non-MoEngage pushes — matches the existing behaviour).

  • Track notification click or dismiss based on the response.

    Declaration

    Swift

    @available(iOSApplicationExtension, unavailable)
    @available(tvOS, unavailable)
    @discardableResult
    @objc
    public func logNotificationClicked(withResponse response: UNNotificationResponse) -> MoEngageLogNotificationTask

    Parameters

    response

    APNS notification response.

    Return Value

    MoEngageLogNotificationTask — same contract as the withPayload variant.

  • Validate if the notification belongs to MoEngage.

    Declaration

    Swift

    @available(tvOS, unavailable)
    @objc
    public func isPushFromMoEngage(withPayload payload: [AnyHashable : Any]) -> Bool

    Parameters

    payload

    APNS notification payload.

    Return Value

    true if the notification belongs to MoEngage, else false.

  • Navigate to push permission settings page.

    Declaration

    Swift

    @available(iOSApplicationExtension, unavailable)
    @discardableResult
    @objc
    public func navigateToPushSettings() -> MoEngageNavigationTask

    Return Value

    MoEngageNavigationTask resolving once the SDK has issued the open-Settings request. Does NOT confirm Settings actually opened on screen (UIApplication.open(_:) completes asynchronously).

  • Checks if the push notification payload is a self-handled background notification. A self-handled background notification is a special type of notification that the app handles in the background without displaying it to the user.

    Declaration

    Swift

    @objc
    public func isSelfHandledBackgroundNotification(payload: [AnyHashable : Any]) -> Bool

    Parameters

    payload

    The push notification payload dictionary.

    Return Value

    true if the notification is a self-handled background notification (notification type is “sh_b”), false otherwise.