Push Content

Notification Content Extension allows you to customize the appearance of the notification in expanded mode. For info on how to create campaigns with templates in the dashboard refer to this link.

STEP:

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

1. Create a Notification Content Extension

After 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 an .plist file associated with it.

2. Set deployment target

Set the deployment target same as the main app target.

3. Add required Capabilities

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

4. Info.plist changes

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

Key
DataType
Value

UNNotificationExtensionCategory

String

AntsomiNotificationContent

UNNotificationExtensionDefaultContentHidden

Boolean

YES

UNNotificationExtensionInitialContentSizeRatio

Number

1

UNNotificationExtensionUserInteractionEnabled

boolean

YES

Note

Update the UNNotificationExtensionCategory with the necessary values according to the categories that you have declared.

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:

6. AntsomiRichNotification Integration

Integration via CocoaPod

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

target 'NotificationContentExtension' do
  pod 'AntsomiFramework'
end

7. Code Changes in Content Extension:

import UIKit
import UserNotifications
import UserNotificationsUI
import AntsomiFramework
  
class NotificationViewController: UIViewController, UNNotificationContentExtension {
    
    func didReceive(_ notification: UNNotification) {
        print("Push Notification Payload \(String(describing: notification.request.content.userInfo))")
        PushTemplateBaseController.handleNotification(withController: self, withNotification: notification);
    }
}

Last updated