> ## Documentation Index
> Fetch the complete documentation index at: https://moengage-gr001-flows-limits.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 7.x.x?

> Fix push impression tracking and image rendering on iOS with Swift SDK 7.x.x. Check appgroupid configuration in your MoEngage project settings.

## 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 7.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 src="https://mintcdn.com/moengage-gr001-flows-limits/2rAYO1ZgWMBNcbKN/images/moengage_a3edc2.png?fit=max&auto=format&n=2rAYO1ZgWMBNcbKN&q=85&s=122cba88de23f8524fae0ec10072ed0a" alt="iOS imp.png" width="2744" height="1582" data-path="images/moengage_a3edc2.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>
     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-gr001-flows-limits/QcZzv--D8ORuD8RF/images/moengage_053674.png?fit=max&auto=format&n=QcZzv--D8ORuD8RF&q=85&s=efd409e26d07b6c4d4872bb8ee116c01" alt="app group.png" width="1920" height="709" data-path="images/moengage_053674.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 src="https://mintcdn.com/moengage-gr001-flows-limits/0VlLik6NltRaK5rz/images/moengage_667e35.png?fit=max&auto=format&n=0VlLik6NltRaK5rz&q=85&s=da8c1dbc8e521413861e000df7e42b96" alt="app id.png" width="1920" height="888" data-path="images/moengage_667e35.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")
   ```
   ```Objective-C 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. **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 src="https://mintcdn.com/moengage-gr001-flows-limits/XyAB1fvO-iq3DU9_/images/moengage_23f29a.png?fit=max&auto=format&n=XyAB1fvO-iq3DU9_&q=85&s=67a5cdc3e257453eafeaa34c994f4820" alt="enable.png" width="1920" height="706" data-path="images/moengage_23f29a.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-gr001-flows-limits/UjvdVG3Sj8SdSKCw/images/moengage_cb3695.png?fit=max&auto=format&n=UjvdVG3Sj8SdSKCw&q=85&s=6e1b7e8efd9db24f366ea19e3ad2bc3f" alt="support.png" width="1920" height="563" data-path="images/moengage_cb3695.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 'MORichNotification'
   end
   ```
5. NotificationService.swift file looks like this:
   ```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 src="https://mintcdn.com/moengage-gr001-flows-limits/Cft0T81CuuuG48G1/images/moengage_cfdd8e.png?fit=max&auto=format&n=Cft0T81CuuuG48G1&q=85&s=d8c6ab70564a5b385752a3a8d3adccee" alt="copy.png" width="1920" height="652" data-path="images/moengage_cfdd8e.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-gr001-flows-limits/s5J_xyCf1zCf9rDo/images/moengage_ef15c5.png?fit=max&auto=format&n=s5J_xyCf1zCf9rDo&q=85&s=f8ede1512a7c390c7e1bc5b7f154c463" alt="run.png" width="1750" height="556" data-path="images/moengage_ef15c5.png" />

<img src="https://mintcdn.com/moengage-gr001-flows-limits/ZTP0MrMRfooCSwjy/images/moengage_7a3664.png?fit=max&auto=format&n=ZTP0MrMRfooCSwjy&q=85&s=8babc571765365547f318232a61c4eb9" alt="build.png" width="1832" height="446" data-path="images/moengage_7a3664.png" />
