Problem
Push templates (carousel images, background color, font color, and so on) do not display correctly in Push notifications when the Notification Content Extension is not implemented.
Instruction
Perform the following steps:
- Create a Notification Content Extension Target.
- Name the Extension Target. Choose a name for the extension target. Swift is recommended as the language as it works seamlessly with Objective-C projects too.
- Add the AppGroupId to the Notification Content Extension’s Signing & Capabilities settings.
- Set the minimum deployment iOS version of the Notification Content Extension to match the main app’s iOS version.
- Integrate the MORichNotification Framework into the Notification Content Extension Target.
- In your podfile, add the Notification Content Extension as a separate target and install the MORichNotification framework.
target 'MoEngageDemo' do use_frameworks! pod 'MoEngage-iOS-SDK' end target 'MoEngageNotificationService' do use_frameworks! #use use_frameworks only if included in main target as in above scenario pod 'MoEngageRichNotification' end target 'MoegageRichContent" do use_frameworks! #use use_frameworks only if included in main target as in above scenario pod 'MoEngageRichNotification' end
- In your podfile, add the Notification Content Extension as a separate target and install the MORichNotification framework.
- Code changes in NotificationViewController.swift file.
import UIKit import UserNotifications import UserNotificationsUI import MoEngageRichNotification class NotificationViewController: UIViewController, UNNotificationContentExtension { @IBOutlet var label: UILabel? override func viewDidLoad() { super.viewDidLoad() MoEngageSDKRichNotification.setAppGroupID("group.com.XXXXXXXXXXXXXXXX") } func didReceive(_ notification: UNNotification) { if #available(iOSApplicationExtension 12.0, *) { MoEngageSDKRichNotification.addPushTemplate(toController: self, withNotification: notification) } else { // Fallback on earlier versions } } }
- Select MainInterface.storyboard in the Content extension, remove the default label, and set the background color of the View to clear.
- Info.plist changes:
<key>NSExtensionAttributes</key>
<dict>
<key>UNNotificationExtensionCategory</key>
<string>MOE_PUSH_TEMPLATE</string>
<key>UNNotificationExtensionDefaultContentHidden</key>
<true/>
<key>UNNotificationExtensionInitialContentSizeRatio</key>
<real>1.2</real>
<key>UNNotificationExtensionUserInteractionEnabled</key>
<true/>
</dict> - Check Build Phases in Main App Target.
- In Embed App Extensions/Embed Foundation Extensions, ensure that Copy only when installing is not selected.
-
Ensure Consistent appGroupId Across Configurations.
- Verify that the appGroupId is consistent across all schemes and configurations (for example, Debug/Release/QA/UAT) in the project.
- Align Build Configuration.
- When running or archiving the project, make sure that the Build Configuration for the Main Target, Notification Service Extension, and Notification Content Extension Target points to the same scheme/configuration.