> ## Documentation Index
> Fetch the complete documentation index at: https://moengage.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# iOS SDK バージョン 8.x.x を使用する iOS デバイスで、プッシュ通知の一般的な問題を回避するにはどうすればよいですか？

> iOS SDK 8.x.x で、プッシュのインプレッショントラッキングと画像レンダリングの問題を解決します。MoEngage iOS アプリ統合で appgroupid を正しく設定します。

## 問題

SDK バージョン 8.x.x で、プッシュ通知がデバイスに正常に配信されているにもかかわらず、プッシュキャンペーンのインプレッションがトラッキングされない、画像がレンダリングされないなど、プッシュ通知に関する一般的な問題が発生しています。

> [!NOTE]
>
> * インプレッションをトラッキングするには、アプリに Notification Service Extension が実装されていることを確認してください。
> * また、MoEngage ダッシュボードで **Settings → Channel → Push → IOS** に移動し、**Show iOS impressions** トグルを有効にしてください。
>
>   ![iOS imp.png](https://mintcdn.com/moengage/xGyg9rXr6djolSrt/images/moengage_dc5648.png?fit=max\&auto=format\&n=xGyg9rXr6djolSrt\&q=85\&s=8a733ef76ea2ffd2991b4d12c34efa2a)

## 解決策

以下の手順を実行します。

1. **各構成について、プロジェクトのメインターゲットに app\_group\_id を追加する**:
   構成間で同じ app\_group\_id を追加することも、異なる app\_group\_id を追加することもできます。
   > [!NOTE]
   >
   > 構成で異なる Bundle Identifier を使用しながら同じ app\_group\_id を共有している場合、問題が発生する可能性があります。具体的には、Bundle Identifier が異なり app\_group\_id が同じ 2 つのアプリが同じデバイスにインストールされている場合、Notification Service Extension が失敗する可能性があります。
   > これを回避するために複数の構成で同じ app\_group\_id を使用できますが、その場合は 1 台のデバイスですべてのアプリを同時にテストできないことに注意してください。
   ![app group.png](https://mintcdn.com/moengage/epqsPEpMsGQCYy1r/images/moengage_5c2e5d.png?fit=max\&auto=format\&n=epqsPEpMsGQCYy1r\&q=85\&s=8917adf4cbaf06eca06f78d52d0783b9)
2. **SDK の初期化時に app\_group\_id を追加する**:
   * info.plist を使用して SDK を初期化する場合は、info.plist ファイルの MoEngage キー内に APP\_GROUP\_ID キーを追加します。
   * sdkConfig を使用して SDK を初期化する場合は、AppDelegate ファイル内の sdkConfig 変数に APP\_GROUP\_ID を追加します。\
     **info.plist 内の app\_group\_id:**

     ![app id.png](https://mintcdn.com/moengage/2kQqTYC5RUPSd8kI/images/moengage_3ef908.png?fit=max\&auto=format\&n=2kQqTYC5RUPSd8kI\&q=85\&s=2d6c7d309bae34a743be23a04270ebda)
   **sdkConfig 変数内の app\_group\_id:**
   ```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. **Notification Service Extension ターゲットを作成する**:

   ![NSE.png](https://mintcdn.com/moengage/ncl4TtlD4tqnPefh/images/moengage_75705c.png?fit=max\&auto=format\&n=ncl4TtlD4tqnPefh\&q=85\&s=48cd4b154056c9a73a69ee87977eacc7)
   * **拡張ターゲットに名前を付ける**: 拡張ターゲットの名前を選択します。Swift は Objective-C プロジェクトともシームレスに連携するため、言語として Swift を推奨します。 ![name.png](https://mintcdn.com/moengage/SBG7um9Fqotw1CFo/images/moengage_b679ab.png?fit=max\&auto=format\&n=SBG7um9Fqotw1CFo\&q=85\&s=72991bfa562181c9694536cbc91c29bd)
   * **プッシュ通知を有効にする**: 拡張ターゲットの Signing & Capabilities セクションで、Push Notifications を有効にし、AppGroupId を追加します。

     ![enable.png](https://mintcdn.com/moengage/cFTwc93vQdTanvKi/images/moengage_bcd3f7.png?fit=max\&auto=format\&n=cFTwc93vQdTanvKi\&q=85\&s=5bcd680aa7e48e28820789117f41d846)
   * **最小デプロイ iOS バージョンを揃える**: Notification Service Extension の最小デプロイ iOS バージョンが、メインアプリの iOS バージョンと一致していることを確認します。 ![support.png](https://mintcdn.com/moengage/DUgG020WbtkVK2Ls/images/moengage_334ceb.png?fit=max\&auto=format\&n=DUgG020WbtkVK2Ls\&q=85\&s=f7acf6f951e4068f402ed50d1939ca90)
4. **MORichNotification フレームワークを Notification Service Extension ターゲットに統合する**: podfile で、Notification Service Extension を別のターゲットとして追加し、MORichNotification フレームワークをインストールします。
   ```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 ファイルのコード変更:
   ```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. **メインアプリターゲットの Build Phases を確認する**: メインアプリターゲットの Build Phases セクションで、Embed App Extensions / Embed Foundation Extensions セクションを見つけます。**Copy only when installing** オプションがオフになっていることを確認します。

   ![copy.png](https://mintcdn.com/moengage/iCae3l_a7eOJMTbz/images/moengage_1e9b68.png?fit=max\&auto=format\&n=iCae3l_a7eOJMTbz\&q=85\&s=52e59705bfa415bafd4c9b696ede2592)
7. **構成間で appGroupId を統一する**: プロジェクト内のすべてのスキームと構成（Debug/Release/QA/UAT など）で appGroupId が統一されていることを確認します。
8. **ビルド構成を揃える**: プロジェクトを実行またはアーカイブする際は、メインターゲットと Notification Service Extension ターゲットの両方の Build Configuration が同じスキーム/構成を指していることを確認します。

   ![run.png](https://mintcdn.com/moengage/dLyLAwgfsm1v6_MY/images/moengage_886b20.png?fit=max\&auto=format\&n=dLyLAwgfsm1v6_MY\&q=85\&s=1d23ce5931914a9982982e181ada1c72)

   ![build.png](https://mintcdn.com/moengage/epqsPEpMsGQCYy1r/images/moengage_5e1a43.png?fit=max\&auto=format\&n=epqsPEpMsGQCYy1r\&q=85\&s=4d13903305650d5d019ad0ce370a63dd)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.