Problem
Push templates (carousel images, background color, font color, and so on) are not displayed correctly in Push notifications when the Notification Content Extension is not implemented.
Instruction
Perform the following steps:
- Create a Notification Content Extension target.
- In the Product Name box, type a name for the extension target.
- In the Language list, click a language. Swift is recommended as the language because it works seamlessly with Objective-C projects.
- On the Signing & Capabilities tab, add the AppGroupId to the Notification Content Extension’s settings.
- Under Minimum Deployments, 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 'MORichNotification' end target 'MoegageRichContent" do use_frameworks! #use use_frameworks only if included in main target as in above scenario pod 'MORichNotification' 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 MORichNotification class NotificationViewController: UIViewController, UNNotificationContentExtension { @IBOutlet var label: UILabel? override func viewDidLoad() { super.viewDidLoad() MORichNotification.setAppGroupID("group.com.XXXXXXXXXXXXXXXX") } func didReceive(_ notification: UNNotification) { if #available(iOSApplicationExtension 12.0, *) { MOPushTemplateHandler.sharedInstance().addPushTemplate(to: self, with: 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 the main app target.
- In Embed App Extensions/Embed Foundation Extensions, clear the Copy only when installing check box.
-
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 executing or archiving the project, ensure that the build configuration for the main target, Notification Service Extension, and Notification Content Extension target points to the same scheme or configuration.