- 
                Notifications
    You must be signed in to change notification settings 
- Fork 22
How to display messages when app is running in the foreground?
        Alexander Boldyrev edited this page Oct 31, 2024 
        ·
        22 revisions
      
    Mobile Messaging SDK has a built-in logic to display Mirror push notifications with a minimum development effort, more details here: Mirror push notifications
In order to display incoming messages (both pushed by APNs and pulled from the server) while your application is running in the foreground, you have to:
- 
Implement MMMessageHandlingDelegateprotocol and it's methodwillPresentInForeground(message:withCompletionHandler:), i.e.:class MyMessageHandlingDelegate : MMMessageHandlingDelegate { func willPresentInForeground(message: MM_MTMessage?, notification: UNNotification, withCompletionHandler completionHandler: @escaping (MMUserNotificationType) -> Void) { completionHandler([.alert, .sound]) // the foreground notification will be displayed on top of the screen with sound } } 
- 
Pass the delegate object to MobileMessaging SDK: MobileMessaging.messageHandlingDelegate = MyMessageHandlingDelegate() 
If you have any questions or suggestions, feel free to send an email to [email protected] or create an issue.