> ## 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 Swift version 8.x.x?

> Fix push impression tracking and image rendering on iOS with Swift SDK 8.x.x. Validate your appgroupid setup during MoEngage SDK initialization.

## 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 Swift version 8.x.x.

<Info>
  For Push Campaign impressions to be tracked, verify that the **Show iOS impressions** toggle on the MoEngage dashboard is turned on.

  <img alt="iOS imp.png" src="https://mintcdn.com/moengage-docs-mcp-segmentation-tool-belt/LWJs2u-oFo9j2Z9M/images/moengage_0e5d8f.png?fit=max&auto=format&n=LWJs2u-oFo9j2Z9M&q=85&s=5db961d45b7dd4d7387e4b65f87eb4f5" width="2744" height="1582" data-path="images/moengage_0e5d8f.png" />
</Info>

## Solution

Perform the following steps:

1. **Check for app\_group\_id in 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/wB_LcY5E-qJXzyQZ/images/moengage_ce154b.png?fit=max&auto=format&n=wB_LcY5E-qJXzyQZ&q=85&s=e7a44b9f3f29914345fcc8559ae7fb91" alt="app group.png" width="1920" height="709" data-path="images/moengage_ce154b.png" />

2. **Check for app\_group\_id during SDK initialization**:
   * If the SDK is initialized using info.plist, the APP\_GROUP\_ID key must be there inside the MoEngage key in your info.plist file.
   * If the SDK is initialized using sdkConfig, the APP\_GROUP\_ID must be in the sdkConfig variable inside the AppDelegate file.\
     **app\_group\_id in info.plist:**
     <img alt="app id.png" src="https://mintcdn.com/moengage-docs-mcp-segmentation-tool-belt/oih9QIk_AcBp_2l9/images/moengage_ae103f.png?fit=max&auto=format&n=oih9QIk_AcBp_2l9&q=85&s=33fd5545af2c0aaa77e117b7fc9b1238" width="1920" height="888" data-path="images/moengage_ae103f.png" />
   **app\_group\_id in sdkConfig variable:**
   ```swift Swift theme={null}
   var sdkConfig = MOSDKConfig.init(withAppID: "XXXXXXXXXXXXXXXX")
   sdkConfig.moeDataCenter = .data\_center\_0X
   sdkConfig.appGroupID = "group.com.XXXXXXXXXXXXXXXX"
   ```
   ```Objective-C Objective-C theme={null}
   MOSDKConfig* sdkConfig = [[MOSDKConfig alloc] initWithAppID: @"XXXXXXXXXXXXXXXX"];
   sdkConfig.moeDataCenter = MODataCenterData_center_0X;
   sdkConfig.appGroupID = @"group.com.XXXXXXXXXXXXXXXX";
   ```

3. **Check for a Notification Service Extension Target**:

   * **Enable Push Notifications**: In the extension target's Signing & Capabilities section, make sure to enable Push Notifications and add the AppGroupId.
     <img alt="enable.png" src="https://mintcdn.com/moengage-docs-mcp-segmentation-tool-belt/A_S_BgA7c7XbbHjJ/images/moengage_a78eb7.png?fit=max&auto=format&n=A_S_BgA7c7XbbHjJ&q=85&s=40b583f924210b46faf7dbada13fc5a5" width="1920" height="706" data-path="images/moengage_a78eb7.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-docs-mcp-segmentation-tool-belt/13cF0SSLXoED7ZnM/images/moengage_036b95.png?fit=max&auto=format&n=13cF0SSLXoED7ZnM&q=85&s=eb0c972a089cac5fb329b8f0d47db32a" width="1920" height="563" data-path="images/moengage_036b95.png" />

4. Integrate the MORichNotification Framework into the Notification Service Extension target.
   ```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 'MoEngageRichNotification'
   end
   ```

5. NotificationService.swift file looks like this:
   ```swift Swift 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) {	
         MORichNotification.setAppGroupID("group.com.XXXXXXXXXXXXXXXX")
         self.contentHandler = contentHandler
         bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)
         MORichNotification.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 alt="copy.png" src="https://mintcdn.com/moengage-docs-mcp-segmentation-tool-belt/S5T4So9_9UMlTMby/images/moengage_20e736.png?fit=max&auto=format&n=S5T4So9_9UMlTMby&q=85&s=f6ee4cf645eaa54336f949372fb1cfe7" width="1920" height="652" data-path="images/moengage_20e736.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 alt="run.png" src="https://mintcdn.com/moengage-docs-mcp-segmentation-tool-belt/-CPXQ8cFB42Sdqri/images/moengage_51ffb0.png?fit=max&auto=format&n=-CPXQ8cFB42Sdqri&q=85&s=bf631a65d2a005f5f67496ba58d80b94" width="1750" height="556" data-path="images/moengage_51ffb0.png" />

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