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

> Fix push impression tracking and image rendering on iOS with Swift SDK 9.x.x. Confirm appgroupid is correctly set in your MoEngage SDK config.

## 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 9.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-limits-analytics/c2y2u-J_HkNQzxk-/images/moengage_74b27d.png?fit=max&auto=format&n=c2y2u-J_HkNQzxk-&q=85&s=3446aa036a588ea143a07f0591b5b2a8" width="2744" height="1582" data-path="images/moengage_74b27d.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-limits-analytics/Z-NsBZQ1-i9hoVMC/images/moengage_edc3d4.png?fit=max&auto=format&n=Z-NsBZQ1-i9hoVMC&q=85&s=45d56369ee202a00d762dc25bc8dc54c" alt="app group.png" width="1920" height="709" data-path="images/moengage_edc3d4.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-limits-analytics/65-4PjaDN9S7-Oqw/images/moengage_c8e4c5.png?fit=max&auto=format&n=65-4PjaDN9S7-Oqw&q=85&s=13c8bc74bedf088f7e37080a5b35b9df" width="1920" height="888" data-path="images/moengage_c8e4c5.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 wrap theme={null}
   MoEngageSDKConfig* sdkConfig = [[MoEngageSDKConfig alloc] initWithAppId:@"XXXXXXXXXXXXXXXX" dataCenter: MoEngageDataCenterData_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-limits-analytics/kC7NLKw4gaFe5HQV/images/moengage_00fc2a.png?fit=max&auto=format&n=kC7NLKw4gaFe5HQV&q=85&s=fefbf09f6453ca34aa2b3a31efc9c6e6" width="1920" height="706" data-path="images/moengage_00fc2a.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-limits-analytics/cgZVFiFRv0ToH_NH/images/moengage_d97c40.png?fit=max&auto=format&n=cgZVFiFRv0ToH_NH&q=85&s=c87cc92f4b1034fba89682c568d6b8b6" width="1920" height="563" data-path="images/moengage_d97c40.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) {	
         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 alt="copy.png" src="https://mintcdn.com/moengage-docs-limits-analytics/X2bQzXQgi7akP73L/images/moengage_76d571.png?fit=max&auto=format&n=X2bQzXQgi7akP73L&q=85&s=34e4453bbf341538ef830af6124a39eb" width="1920" height="652" data-path="images/moengage_76d571.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-limits-analytics/2RDaEcJHg_cGhez4/images/moengage_4e6070.png?fit=max&auto=format&n=2RDaEcJHg_cGhez4&q=85&s=0bd8de7aba87c180c06e091cce14675a" width="1750" height="556" data-path="images/moengage_4e6070.png" />
   <img alt="build.png" src="https://mintcdn.com/moengage-docs-limits-analytics/v6qRKtN3oEt8xIYv/images/moengage_ab8f19.png?fit=max&auto=format&n=v6qRKtN3oEt8xIYv&q=85&s=6e066b9f6c5d017910351376d41a658a" width="1832" height="446" data-path="images/moengage_ab8f19.png" />
