How to Avoid Push Template Issues in iOS Push Notifications (SDK version 7.x.x) Without a Notification Content Extension?

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:

  1. Create a Notification Content Extension target.NCE.png
    • 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.name swift.png
    • On the Signing & Capabilities tab, add the AppGroupId to the Notification Content Extension’s settings.signing.png
    • Under Minimum Deployments, 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 'MORichNotification'
      end
      
      target 'MoegageRichContent" do
        use_frameworks! #use use_frameworks only if included in main target as in above scenario
        pod 'MORichNotification'
      end
  3. Code changes in NotificationViewController.swift file.
    Swift
    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
            }
        }
    }
  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 the main app target. 
    • In Embed App Extensions/Embed Foundation Extensions, clear the Copy only when installing check box.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 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.

    debug.png

    target.png

    duplicate.png

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

How can we improve this article?