-
Couldn't load subscription status.
- Fork 22
How to display messages when app is running in the foreground?
Davor Komušanac edited this page Dec 5, 2022
·
22 revisions
Mobile Messaging SDK has a built-in logic to display in-app messages with a minimum development effort, more details here: In-app 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.messageHandlindDelegate = MyMessageHandlingDelegate()
If you have any questions or suggestions, feel free to send an email to [email protected] or create an issue.