> ## Documentation Index
> Fetch the complete documentation index at: https://moengage-analytics-query-api-docs.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# How to Avoid Common Push Notification Issues on iOS Devices Using iOS SDK version 7.x.x?

> Fix push campaign impression tracking and image rendering on iOS SDK 7.x.x. Step-by-step guide to configuring appgroupid in your MoEngage setup.

## Problem

Common issues with Push notifications, including Push Campaign impressions not being tracked and images not rendering even though Push notifications are successfully delivered to device with SDK version 7.x.x.

<Info>
  * To track impressions, ensure that the Notification Service Extension is implemented in your app.
  * Additionally, enable the **Show iOS impressions** toggle on the MoEngage dashboard by navigating to **Settings → Channel → Push → IOS**.
      <img alt="iOS imp.png" src="https://mintcdn.com/moengage-analytics-query-api-docs/K1ZWgXTR7uO5BTh8/images/moengage_b3e15a.png?fit=max&auto=format&n=K1ZWgXTR7uO5BTh8&q=85&s=36bfb4632f2daf16025a34feb8f63be5" width="2744" height="1582" data-path="images/moengage_b3e15a.png" />
</Info>

## Solution

Perform the following steps:

1. **Add app\_group\_id to Your Project’s Main Target for Each Configuration**:
   You can add the same app\_group\_id or different ones across configurations.
   <Info>
     If your configurations use different Bundle Identifiers but share the same app\_group\_id, issues may arise. Specifically, if two apps with different Bundle Identifiers but the same app\_group\_id are installed on the same device, the Notification Service Extension may fail.
     To avoid this, you can use the same app\_group\_id across multiple configurations, but be aware that you won't be able to test all apps simultaneously on a single device.
   </Info>
   <img src="https://mintcdn.com/moengage-analytics-query-api-docs/eJTcJrF1-vmsOukF/images/moengage_6f8ef6.png?fit=max&auto=format&n=eJTcJrF1-vmsOukF&q=85&s=6cb8f0fdd902a55143d5f97ed41f98dc" alt="app group.png" width="1920" height="709" data-path="images/moengage_6f8ef6.png" />
2. **Add app\_group\_id During SDK Initialization**:
   * If you initialize the SDK using info.plist, add the APP\_GROUP\_ID key inside the MoEngage key in your info.plist file.
   * If you initialize the SDK using sdkConfig, add the APP\_GROUP\_ID in the sdkConfig variable inside the AppDelegate file.\
     **app\_group\_id in info.plist:**
     <img alt="app id.png" src="https://mintcdn.com/moengage-analytics-query-api-docs/8GscUheGMO8Wf0AE/images/moengage_2f7c53.png?fit=max&auto=format&n=8GscUheGMO8Wf0AE&q=85&s=2851059eb5c714542d026fd03e10218f" width="1920" height="888" data-path="images/moengage_2f7c53.png" />
   **app\_group\_id in sdkConfig variable:**
   ```swift Swift theme={null}
   var sdkConfig = MOSDKConfig.init(appID: "XXXXXXXXXXXXXXXX")
   sdkConfig.moeDataCenter = DATA_CENTER_0X
   sdkConfig.appGroupID = "group.com.XXXXXXXXXXXXXXXX"
   //if SDK initialized without sdkConfig in AppDelegate file
   MoEngage.setAppGroupID("group.com.moengage.MIPL567.demo")
   ```
   ```swift Objective-C theme={null}
   MOSDKConfig* sdkConfig = [[MOSDKConfig alloc] initWithAppID: @"XXXXXXXXXXXXXXXX"];
   sdkConfig.moeDataCenter = DATA_CENTER_0X;
   sdkConfig.appGroupID = @"group.com.XXXXXXXXXXXXXXXX";
   //if SDK initialized without sdkConfig in AppDelegate file
   [MoEngage setAppGroupID: @"group.com.XXXXXXXXXXXXXXXX"];
   ```
3. **Create a Notification Service Extension Target**:
   <img alt="NSE.png" src="https://mintcdn.com/moengage-analytics-query-api-docs/e-xTJgaB2EK9nPFr/images/moengage_ecada5.png?fit=max&auto=format&n=e-xTJgaB2EK9nPFr&q=85&s=738468a96098d5578f691ae8177734a4" width="1432" height="1008" data-path="images/moengage_ecada5.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. <img alt="name.png" src="https://mintcdn.com/moengage-analytics-query-api-docs/EmRO673igszh_zlm/images/moengage_1a574b.png?fit=max&auto=format&n=EmRO673igszh_zlm&q=85&s=f320a109c22df42d1f93215c0d2749c2" width="1440" height="1012" data-path="images/moengage_1a574b.png" />
   * **Enable Push Notifications**: In the extension target's Signing & Capabilities section, enable Push Notifications and add the AppGroupId.
     <img alt="enable.png" src="https://mintcdn.com/moengage-analytics-query-api-docs/4z-ZT8IqbQMGLjHJ/images/moengage_67a2f5.png?fit=max&auto=format&n=4z-ZT8IqbQMGLjHJ&q=85&s=9951f044d64b4305f0dfd8650b0b26bc" width="1920" height="706" data-path="images/moengage_67a2f5.png" />
   * **Align the Minimum Deployment iOS Version**: Ensure that the minimum deployment iOS version of the Notification Service Extension matches the iOS version of the main app. <img alt="support.png" src="https://mintcdn.com/moengage-analytics-query-api-docs/bQNodCx4rVX2jftR/images/moengage_9719f4.png?fit=max&auto=format&n=bQNodCx4rVX2jftR&q=85&s=f9069a8adda9c244dda97717714f25e4" width="1920" height="563" data-path="images/moengage_9719f4.png" />
4. **Integrate the MORichNotification Framework into the Notification Service Extension Target**: In your podfile, add the Notification Service Extension as a separate target and install the MORichNotification framework.
   ```swift Swift theme={null}
   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
   ```
5. Code changes in NotificationService.swift file:
   ```swift Swift theme={null}
   import UserNotifications
   import MORichNotification
    
   class NotificationService: UNNotificationServiceExtension {
    
       var contentHandler: ((UNNotificationContent) - Void)?
       var bestAttemptContent: UNMutableNotificationContent?
    
       override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) - Void) {	
         MORichNotification.setAppGroupID("group.com.XXXXXXXXXXXXXXXX")
         self.contentHandler = contentHandler
         bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)
         MORichNotification.handle(request, withContentHandler: contentHandler)
       }
       
       override func serviceExtensionTimeWillExpire() {
           // Called just before the extension will be terminated by the system.
           // Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used.
           if let contentHandler = contentHandler, let bestAttemptContent =  bestAttemptContent {
               contentHandler(bestAttemptContent)
           }
       }
   }
   ```
6. **Check Build Phases for the Main App Target**: In the Build Phases section of the main app target, locate the Embed App Extensions / Embed Foundation Extensions section. Ensure that the **Copy only when installing** option is unchecked.
   <img alt="copy.png" src="https://mintcdn.com/moengage-analytics-query-api-docs/FeDOaUaZp6fDSte_/images/moengage_7feeda.png?fit=max&auto=format&n=FeDOaUaZp6fDSte_&q=85&s=bbbcaf8738a01e64a850704fb40e9b1f" width="1920" height="652" data-path="images/moengage_7feeda.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 both the Main Target and the Notification Service Extension Target points to the same scheme/configuration.
   <img alt="run.png" src="https://mintcdn.com/moengage-analytics-query-api-docs/eJTcJrF1-vmsOukF/images/moengage_6fb391.png?fit=max&auto=format&n=eJTcJrF1-vmsOukF&q=85&s=14bafba902fbed8eb1d4535d3035fdab" width="1750" height="556" data-path="images/moengage_6fb391.png" />
   <img alt="build.png" src="https://mintcdn.com/moengage-analytics-query-api-docs/ifN61nrduWX4LCim/images/moengage_a30419.png?fit=max&auto=format&n=ifN61nrduWX4LCim&q=85&s=e3ffa477f843a2f31362cc4a4b61ffdf" width="1832" height="446" data-path="images/moengage_a30419.png" />
