Skip to content

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

Andrey Kadochnikov edited this page Jan 30, 2018 · 8 revisions

In order to handle user tap on notification alert:

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

    class MyMessageHandlingDelegate : MessageHandlingDelegate {
        func didPerform(action: NotificationAction, forMessage message: MTMessage, 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.sharedInstance?.messageHandlindDelegate = MyMessageHandlingDelegate()
Clone this wiki locally