Skip to content

How to display messages when app is running in the foreground?

Alexander Boldyrev edited this page Jul 31, 2025 · 3 revisions

Using built-in Mirror push notification feature

Mobile Messaging SDK has a built-in logic to display Mirror push notifications with a minimum development effort, more details here: Mirror push notifications

Writing a custom handler

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 MMMessageHandlingDelegate protocol and its method willPresentInForeground(message:withCompletionHandler:). Then you have to pass the delegate object to the MobileMessaging SDK as shown below:

//AppDelegate.m

#import "AppDelegate.h"
#import "MainViewController.h"
+#import "<ApplicationName>-Swift.h"
+@import MobileMessaging;

@implementation AppDelegate
 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary<UIApplicationLaunchOptionsKey, id> *)launchOptions
{
    self.viewController = [[MainViewController alloc] init];
    
+   MobileMessaging.messageHandlingDelegate = [CustomMessageHandlingDelegate new];
    
    return [super application:application didFinishLaunchingWithOptions:launchOptions];
}

@end

For detailed examples of how to implement this CustomMessageHandlingDelegate refer to the iOS SDK documentation.

Android - Using withBannerForegroundNotificationsEnabled

From the plugin version 7.2.1 onwards, a feature to always display Push notifications as Banner was introduced to Android SDK.

MobileMessaging.init({
    applicationCode: '<YOUR_APP_CODE>',
    android: {
        withBannerForegroundNotificationsEnabled: true
    }
})

Notice:

Using this parameter together with sending MODAL mirror in-app notifications will result in showing both MODAL and BANNER notifications simultaneously.

Clone this wiki locally