Skip to content

How to handle a message when user opens the app by tapping on a notification alert?

Davor Komušanac edited this page Dec 5, 2022 · 8 revisions

In order to handle user tap on notification alert:

  1. Implement MMMessageHandlingDelegate protocol and it's method didPerform(action:forMessage:completion:), i.e.:

    class MyMessageHandlingDelegate : MMMessageHandlingDelegate {
        func didPerform(action: MMNotificationAction, forMessage message: MM_MTMessage?, notificationUserInfo: [String: Any]?, completion: @escaping () -> Void) {
            if action.isTapOnNotificationAlert { // here you check if the action is indeed a tap on alert
                print("Message with text: \(message.text) was tapped")       
            }
            // don't forget to call `completion`, it's very important to tell the system that action handling is finished
            completion()
        }
    }
  2. Pass the delegate object to MobileMessaging SDK:

    MobileMessaging.messageHandlindDelegate = MyMessageHandlingDelegate()
Clone this wiki locally