> ## Documentation Index
> Fetch the complete documentation index at: https://moengage-doc-2298-s2s-type-case-sensitive.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 8.x.x?

> Resolve push impression tracking and image rendering on iOS SDK 8.x.x. Configure appgroupid correctly for your MoEngage iOS app integration.

## 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 8.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-doc-2298-s2s-type-case-sensitive/DsxY-_SdC8khvAqb/images/moengage_dc5648.png?fit=max&auto=format&n=DsxY-_SdC8khvAqb&q=85&s=7aa61dc5ac133d9b920ead00fad3cfa2" width="2744" height="1582" data-path="images/moengage_dc5648.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-doc-2298-s2s-type-case-sensitive/Rs6MNSgJTu1-kPs5/images/moengage_5c2e5d.png?fit=max&auto=format&n=Rs6MNSgJTu1-kPs5&q=85&s=d15b99584ee19b766077ed2e03b48852" alt="app group.png" width="1920" height="709" data-path="images/moengage_5c2e5d.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-doc-2298-s2s-type-case-sensitive/_i58rwn7D-oeqDXo/images/moengage_3ef908.png?fit=max&auto=format&n=_i58rwn7D-oeqDXo&q=85&s=e6f1cc88d9733ad10c23df99b36ee56b" width="1920" height="888" data-path="images/moengage_3ef908.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. **Create a Notification Service Extension Target**:
   <img alt="NSE.png" src="https://mintcdn.com/moengage-doc-2298-s2s-type-case-sensitive/LmSUEHg0pbjR8OeI/images/moengage_75705c.png?fit=max&auto=format&n=LmSUEHg0pbjR8OeI&q=85&s=13ea1baf90a4269751a8053cbef96ab7" width="1432" height="1008" data-path="images/moengage_75705c.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-doc-2298-s2s-type-case-sensitive/sXShQsUMW-YS9j0C/images/moengage_b679ab.png?fit=max&auto=format&n=sXShQsUMW-YS9j0C&q=85&s=56850acb45d22be92760c48249f99313" width="1440" height="1012" data-path="images/moengage_b679ab.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-doc-2298-s2s-type-case-sensitive/tSxaMl4Ci025EX_c/images/moengage_bcd3f7.png?fit=max&auto=format&n=tSxaMl4Ci025EX_c&q=85&s=3a583082dc2d5cccfae17701fe609d65" width="1920" height="706" data-path="images/moengage_bcd3f7.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-doc-2298-s2s-type-case-sensitive/TCFmbUGdo55wIDrc/images/moengage_334ceb.png?fit=max&auto=format&n=TCFmbUGdo55wIDrc&q=85&s=ba217f92c66e8f604b95ab718cd7f0e7" width="1920" height="563" data-path="images/moengage_334ceb.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 'MoEngageRichNotification'
   end
   ```
5. Code changes in NotificationService.swift file:
   ```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-doc-2298-s2s-type-case-sensitive/UqpZ5Z0TWMUJhlPT/images/moengage_1e9b68.png?fit=max&auto=format&n=UqpZ5Z0TWMUJhlPT&q=85&s=7108da162f3ffccab7c4cb4030a2b2b8" width="1920" height="652" data-path="images/moengage_1e9b68.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, 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-doc-2298-s2s-type-case-sensitive/5MMzN4m1fEgMFLAu/images/moengage_886b20.png?fit=max&auto=format&n=5MMzN4m1fEgMFLAu&q=85&s=06ef35ddad9688d73a1eb3a2821369e4" width="1750" height="556" data-path="images/moengage_886b20.png" />
   <img alt="build.png" src="https://mintcdn.com/moengage-doc-2298-s2s-type-case-sensitive/Rs6MNSgJTu1-kPs5/images/moengage_5e1a43.png?fit=max&auto=format&n=Rs6MNSgJTu1-kPs5&q=85&s=3718587f6fc922f32ee664c9c34f56fa" width="1832" height="446" data-path="images/moengage_5e1a43.png" />
