Skip to content

In app messages

Alexander Boldyrev edited this page Oct 31, 2024 · 1 revision

Intro

In-App messages are a type of communication tool with mobile users that includes banners, pop-ups and other formats that appear on screen of mobile applications while users are interacting with it. Read more documentation

Notice

Previously known as Full-featured In-App notifications.

In-App messages

Feature is available since 11.0.0 version.

Enabling In-App messages

In-App messages are disabled by default, and in order to enable them, you need to call .withFullFeaturedInApps() method. Without enabling In-App messages MMNotificationMessageReceived event is triggered, but In-App message is not processed and not displayed within WebView.

Notice

Enabling this feature also enables JavaScript execution on the webView for the feature proper work.

MobileMessaging
    .withApplicationCode(<#your application code#>, notificationType: <#for example MMUserNotificationType(options: [.alert, .sound])#>)?
    ...
    .withFullFeaturedInApps()
    .start()
expand to see Objective-C code

    [[[MobileMessaging withApplicationCode: <#your application code#> notificationType: <#your preferred MMUserNotificationType#>]
        withFullFeaturedInApps]
        start:nil];

Send notification

After Mobile Messaging SDK is integrated into your app, you just need to create a Flow in Infobip Customer Portal, choose "Send In-App message" element and select "New messages", In-App message Editor will be opened, where you can create In-App message according to your preferences.

In-App message types
Banner Pop-up Fullscreen
Banner Popup Fullscreen

Additional notes

  • If you do not enable the feature, or use older versions of Mobile Messaging SDK, without this feature support, MMNotificationMessageReceived event will be triggered for this type of messages, but they won't be processed and displayed within WebView.

  • For In-App messages, MM_MTMessage object in the parameter text contains text "In-App", for the technical reasons, but this parameter won't be involved in the process of the displaying In-App messages

Setup custom view controller for presenting in-app

By default, In-App messages or web view, which opens by tapping In-App will be presented on the topmost visible view controller, but in case you have a complex UI hierarchy and the common solution doesn't fit, this behaviour could be changed.

  1. Implement MMMessageHandlingDelegate protocol and it's method inAppPresentingViewController(for message: MM_MTMessage) -> UIViewController?, for example:

    //Swift
    class MyMessageHandlingDelegate : MMMessageHandlingDelegate {
        func inAppPresentingViewController(for message: MM_MTMessage) -> UIViewController? {
            return UIApplication.shared.keyWindow?.rootViewController
        }
    }
    expand to see Objective-C code

    //Objective-C
    @interface MyMessageHandlingDelegate : NSObject <MMMessageHandlingDelegate>
    @end
    
    @implementation MyMessageHandlingDelegate
    - (UIViewController *)inAppPresentingViewControllerFor:(MM_MTMessage *)message {
         return UIApplication.sharedApplication.keyWindow.rootViewController;
    }
    @end

This method should return a view controller that would be used by MobileMessaging SDK as a presenting parent view controller for the In-App or In-App web view. UIApplication.shared.keyWindow?.rootViewController in this example is the simplest general solution that fits many simple iOS applications, however you should provide your own specific view controller, which fits your UI hierarchy.

  1. Pass the custom MessageHandlingDelegate object to MobileMessaging SDK:

    //Swift
    class MyMessageHandlingDelegate : MMMessageHandlingDelegate {
        ...
    }
    //Swift
    MobileMessaging.messageHandlingDelegate = MyMessageHandlingDelegate()
    expand to see Objective-C code

    //Objective-C
    @interface MyMessageHandlingDelegate : NSObject <MMMessageHandlingDelegate>
    @end
    
    @implementation MyMessageHandlingDelegate
    @end
    //Objective-C
    MobileMessaging.messageHandlingDelegate = [MyMessageHandlingDelegate new];

Handling tap on In-App message

Following on-tap actions are supported for the Banner and for the action buttons of other In-App message types:

More information can be found on the How to define specific action on notification or in-app primary button tap(open url, deeplink)?.

Additionally, MobileMessaging SDK will trigger:

  • MMNotificationMessageTapped event if user tapped the banner In-App message
  • MMNotificationActionTapped event if user tapped action button of the Pop-up or Fullscreen notification
  • method didPerform(action: MMNotificationAction, forMessage message: MM_MTMessage?, notificationUserInfo: [String: Any]?, completion: @escaping () -> Void) of the MMMessageHandlingDelegate(How to setup custom MessageHandlingDelegate)

Disable In-App messages

It's possible to disable the Mirror push notification and In-App messages by specifying return value in the following method of custom MessageHandlingDelegate (How to setup custom MessageHandlingDelegate):

    class MyMessageHandlingDelegate : MMMessageHandlingDelegate {
        func shouldShowModalInAppNotification(for message: MM_MTMessage) -> Bool {
            return false
        }
    }
expand to see Objective-C code

    //Objective-C
    @interface MyMessageHandlingDelegate : NSObject <MMMessageHandlingDelegate>
    @end

    @implementation MyMessageHandlingDelegate
    - (BOOL)shouldShowModalInAppNotificationFor:(MM_MTMessage *)message {
         return false;
    }
    @end
Clone this wiki locally