Push Templates 7.x.x

Starting from MoEngage iOS SDK version 6.2.0 and MORichNotification version 4.0.0, push templates will be supported where you would be able to customize the way notification looks in expanded mode. This feature is supported in iOS 12.0 and above. For info on how to create campaigns with templates in the dashboard refer to this link.

info

iOS 15.0 Update

With iOS 15.0 update, we have released MORichNotification version 5.2.0 where for iOS 15.0 and above we have updated the layout to show content at the top and media at bottom, to have it in line with the standard notification layout.

gif_content_extension.gif

library_add_check

Prerequisites

Make sure you have completed the App Target and Notification Service Extension Implementation for supporting Rich Push in your project before proceeding with the below steps.

STEPS:

For supporting these custom push templates, your project needs to have a Notification Content Extension. Follow the below steps to create Content Extension and to set it up to support MoEngage templates:

1. Create a Notification Content Extension

c3651e4-Screenshot_2020-09-03_at_11.23.51.png226b347-Screenshot_2020-09-03_at_11.24.31.png

Once the target is created, Activate the scheme for Extension when prompted for the same. After this, your extension will be added to the project you will see a class with the extension name provided by you while creating and .plist file associated with it.

2. Set deployment target and Add Required frameworks

Now set the deployment target to iOS 12.0 or above, since we support this feature from iOS 12.0. After that add UserNotifications.framework and UserNotificationsUI.framework in Frameworks and Libraries as shown below:

2f19f14-Screenshot_2020-09-03_at_11.26.22.png

3. Add required Capabilities

In Capabilities Section add App Groups and select the same app group id which you have configured in your App target and Notification Service Extension target.

25c5437-Screenshot_2020-09-03_at_11.26.04.png

info

App Group ID Recommendation:

We recommend having a separate App Group ID set for MoEngage with the format group.{app bundle id}.MoEngage. And make sure the same app group id is enabled for all the targets where MoEngage is being used.

4. Info.plist changes

64d3562-Screenshot_2021-09-21_at_12.02.18.png

Make the changes in the Info.plist of your Notification Content Extension, as shown above, set NSExtensionAttributes as following:

Attribute Attribute Value
UNNotificationExtensionCategory MOE_PUSH_TEMPLATE
UNNotificationExtensionInitialContentSizeRatio 1.2
UNNotificationExtensionDefaultContentHidden YES
UNNotificationExtensionUserInteractionEnabled YES

5. Storyboard changes

Select MainInterface.storyboard in your Content extension and remove the default label which is placed there and set the background color of the view to clear color, as shown below:

a9dd50f-Screenshot_2020-09-03_at_11.27.52.png

6. MORichNotification Integration

For integrating through CocoaPod, include MORichNotification pod for your Notification Content Extension as shown below, and run pod update / install command :

Ruby
target "PushTemplatesExtension" do
	pod 'MORichNotification','~>5.0.0'
end
info

Manual Integration

  • To integrate the MORichNotification SDK manually to your project follow this doc.

  • Add MORichNotification to embedded binaries in the App target, and ensure it is linked to your Notification Content Extension target.

7. Code Changes in Content Extension:

Swift Objective-C
import UIKit
import UserNotifications
import UserNotificationsUI
import MORichNotification
  
class NotificationViewController: UIViewController, UNNotificationContentExtension {
    override func viewDidLoad() {
        super.viewDidLoad()
        // Set App Group ID
        MORichNotification.setAppGroupID("Your App Group ID")
    }
  
    
    func didReceive(_ notification: UNNotification) {
        // Method to add template to UI
        MOPushTemplateHandler.sharedInstance().addPushTemplate(to: self, with: notification)
    }

}

As shown above, make these changes in your NotificationViewController class:

  1. Set the same App Group ID in viewDidLoad() method which was enabled in Capabilities[Recommended: group.{app bundle id}.MoEngage]
  2. Call MOPushTemplateHandler method to add template in didReceiveNotification() callback.

8. Notification Click callback in App:

In the case of Simple Image Carousel notification, to know which slide was clicked by the user, make use of MOMessagingDelegate to get notificationClicked(withScreenName: andKVPairs:) callback to get key-value pairs and screen name if set for the clicked slide. Refer to the example below, here we are registering for the callback in AppDelegate:

Swift Objective-C
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate, MOMessagingDelegate{
    
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
      // Set the delegate 
      MOMessaging.sharedInstance().messagingDelegate = self
      //Rest of the implementation
}

// Notification Clicked Callback
func notificationClicked(withScreenName screenName: String?, andKVPairs kvPairs: [AnyHashable : Any]?) {
        if let screenName = screenName {
            print("Navigate to Screen:\(screenName)")
        }
        
        if let actionKVPairs = kvPairs {
            print("Selected Action KVPair:\(actionKVPairs)")
        }
}
  
// Notification Clicked Callback with Push Payload
func notificationClicked(withScreenName screenName: String?, kvPairs: [AnyHashable : Any]?, andPushPayload userInfo: [AnyHashable : Any]) {
        
        print("Push Payload: \(userInfo)")
        
        if let screenName = screenName {
            print("Navigate to Screen:\(screenName)")
        }
        
        if let actionKVPairs = kvPairs {
            print("Selected Action KVPair:\(actionKVPairs)")
        }
}
}

This callback will also be called for normal and Stylized Basic Notifications and could be made use of there as well.

Previous

Next

Was this article helpful?
0 out of 0 found this helpful

How can we improve this article?