> ## Documentation Index
> Fetch the complete documentation index at: https://moengage-docs-mcp-segmentation-tool-belt.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 9.x.x?

> Resolve push impression tracking and image rendering on iOS SDK 9.x.x. Properly set up appgroupid during initialization for your MoEngage project.

## 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 9.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 src="https://mintcdn.com/moengage-docs-mcp-segmentation-tool-belt/VCx-rrlwcgKWhL3G/images/moengage_c44d55.png?fit=max&auto=format&n=VCx-rrlwcgKWhL3G&q=85&s=393ef6f51490556d46309d0490f430df" alt="iOS imp.png" width="2744" height="1582" data-path="images/moengage_c44d55.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>
     Issues may arise if your configurations use different Bundle Identifiers but share the same app\_group\_id. Specifically, the Notification Service Extension may fail if two apps with different Bundle Identifiers but the same app\_group\_id are installed on the same device. 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-docs-mcp-segmentation-tool-belt/1BrXMb0d-10uUGgb/images/moengage_12ce78.png?fit=max&auto=format&n=1BrXMb0d-10uUGgb&q=85&s=119c7a6c4b74610fa3da1b2df3655cd9" alt="app group.png" width="1920" height="709" data-path="images/moengage_12ce78.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 src="https://mintcdn.com/moengage-docs-mcp-segmentation-tool-belt/S59VNXdVKjRvWjBD/images/moengage_9c01e1.png?fit=max&auto=format&n=S59VNXdVKjRvWjBD&q=85&s=2a5148d3ee351229fc79f44d2a2046e5" alt="app id.png" width="1920" height="888" data-path="images/moengage_9c01e1.png" />
     **app\_group\_id in sdkConfig variable:**
   ```swift Swift wrap theme={null}
   var sdkConfig = MoEngageSDKConfig.init(appId: "XXXXXXXXXXXXXXXX", dataCenter: .data_center_0X)
   sdkConfig.appGroupID = "group.com.XXXXXXXXXXXXXXXX"
   ```
   ```Objective-C Objective-C theme={null}
   MoEngageSDKConfig\* sdkConfig = [[MoEngageSDKConfig alloc] initWithAppId:@"XXXXXXXXXXXXXXXX" dataCenter: MoEngageDataCenterData\_center\_0X];
   sdkConfig.appGroupID = @"group.com.XXXXXXXXXXXXXXXX";
   ```
3. **Create a Notification Service Extension Target**:

<img src="https://mintcdn.com/moengage-docs-mcp-segmentation-tool-belt/VCx-rrlwcgKWhL3G/images/moengage_c5e031.png?fit=max&auto=format&n=VCx-rrlwcgKWhL3G&q=85&s=bc449244619d24a8077684313b781475" alt="NSE.png" width="1432" height="1008" data-path="images/moengage_c5e031.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 src="https://mintcdn.com/moengage-docs-mcp-segmentation-tool-belt/bJsJ57ae-ck_LJDJ/images/moengage_4650b5.png?fit=max&auto=format&n=bJsJ57ae-ck_LJDJ&q=85&s=95f3e61f7c607c85ad51f1f02bdd642a" alt="name.png" width="1440" height="1012" data-path="images/moengage_4650b5.png" />

* **Enable Push Notifications**: In the extension target's Signing & Capabilities section, enable Push Notifications and add the AppGroupId.

<img src="https://mintcdn.com/moengage-docs-mcp-segmentation-tool-belt/Jaa5QOpd37_-QiIS/images/moengage_8a8ac1.png?fit=max&auto=format&n=Jaa5QOpd37_-QiIS&q=85&s=316c7e3fdd85a98e4e2f8f2af7cd9a8e" alt="enable.png" width="1920" height="706" data-path="images/moengage_8a8ac1.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 src="https://mintcdn.com/moengage-docs-mcp-segmentation-tool-belt/S9xIkrT8Dn--NtXQ/images/moengage_902c4b.png?fit=max&auto=format&n=S9xIkrT8Dn--NtXQ&q=85&s=8b798c18a5129d55a357214e3417a9e6" alt="support.png" width="1920" height="563" data-path="images/moengage_902c4b.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 wrap 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 'MoEngageRichNotification'
   end
   ```
5. Code changes in NotificationService.swift file:
   ```swift Swift wrap theme={null}
   import UserNotifications
   import MoEngageRichNotification
   class NotificationService: UNNotificationServiceExtension {
      
      var contentHandler: ((UNNotificationContent) - Void)?
      var bestAttemptContent: UNMutableNotificationContent?
      
      override func didReceive(\_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) - Void) {
   MoEngageSDKRichNotification.setAppGroupID("group.com.XXXXXXXXXXXXXXXX")
      
      self.contentHandler = contentHandler
      bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)
      MoEngageSDKRichNotification.handle(richNotificationRequest: 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 src="https://mintcdn.com/moengage-docs-mcp-segmentation-tool-belt/zRW6xyT_cy4duKmT/images/moengage_e8673d.png?fit=max&auto=format&n=zRW6xyT_cy4duKmT&q=85&s=0c9a7d540577efb2fa622cc4f39b3528" alt="copy.png" width="1920" height="652" data-path="images/moengage_e8673d.png" />

7. **Ensure Consistent appGroupId Across Configurations**: Verify that the appGroupId is consistent across all schemes and configurations (e.g. Debug/Release/QA/UAT) in the project.
8. **Align Build Configuration**: When running or archiving the project, ensure that the Build Configuration for the Main Target and Notification Service Extension Target points to the same scheme/configuration.

<img src="https://mintcdn.com/moengage-docs-mcp-segmentation-tool-belt/W-gn6HWUtBpKHBRF/images/moengage_977ad1.png?fit=max&auto=format&n=W-gn6HWUtBpKHBRF&q=85&s=c66ab5700517f51824bfbf544b0210bb" alt="run.png" width="1750" height="556" data-path="images/moengage_977ad1.png" />

<img src="https://mintcdn.com/moengage-docs-mcp-segmentation-tool-belt/oih9QIk_AcBp_2l9/images/moengage_adf541.png?fit=max&auto=format&n=oih9QIk_AcBp_2l9&q=85&s=1e70bcaf6eff26e7d592c7afbc6eb6e5" alt="build.png" width="1832" height="446" data-path="images/moengage_adf541.png" />
