How to Avoid Push Template Issues in iOS Push Notifications (SDK version 8.x.x) When Notification Content Extension is Not Implemented?

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:

  1. Create a Notification Content Extension Target.NCE.png
    • 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.name swift.png
    • Add the AppGroupId to the Notification Content Extension’s Signing & Capabilities settings.signing.png
    • Set the minimum deployment iOS version of the Notification Content Extension to match the main app’s iOS version.deployment.png
  2. 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.
      Swift
      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
  3. Code changes in NotificationViewController.swift file.
    Swift
    import UIKit
    import UserNotifications
    import UserNotificationsUI
    import MoEngageRichNotification
    
    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, *) {
                MORichNotification.addPushTemplate(toController: self, withNotification: notification) 
            } else {
                // Fallback on earlier versions
            }
        }
    }
  4. Select MainInterface.storyboard in the Content extension, remove the default label, and set the background color of the View to clear.main.png
  5. Info.plist changes:
    Swift
    <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>
    NSExtension.png
  6. Check Build Phases in Main App Target. 
    • In Embed App Extensions/Embed Foundation Extensions, ensure that Copy only when installing is not selected.copy only.png
  7. 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.
  8. 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.

    debug.png

    target.png

    duplicate.png

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

How can we improve this article?