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

> Objective-C SDK 8.x.x を使用する iOS で、プッシュのインプレッショントラッキングと画像レンダリングの問題を解決します。MoEngage 統合の appgroupid 設定を確認します。

## 問題

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

> [!NOTE]
>
> プッシュキャンペーンのインプレッションをトラッキングするには、MoEngage ダッシュボードで **Show iOS impressions** トグルがオンになっていることを確認してください。
>
> ![iOS imp.png](https://mintcdn.com/moengage/wjYnJKL0xml-g3HM/images/moengage_458274.png?fit=max\&auto=format\&n=wjYnJKL0xml-g3HM\&q=85\&s=d5366998ba21f2ec3a8006ac8178d752)

## 解決策

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

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/0iWkm50wROjmHH3Z/images/moengage_d35dec.png?fit=max\&auto=format\&n=0iWkm50wROjmHH3Z\&q=85\&s=84d835c5f6506049ef1ef9c4889cee5b)
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/QRy8rcYszbTJNwGr/images/moengage_b4b13a.png?fit=max\&auto=format\&n=QRy8rcYszbTJNwGr\&q=85\&s=625821581425efb04ec444d7c98757ed)

     **sdkConfig 変数内の app\_group\_id:**
   ```objective-c Objective-C wrap theme={null}
   MOSDKConfig\* sdkConfig = [[MOSDKConfig alloc] initWithAppID: @"XXXXXXXXXXXXXXXX"];
   sdkConfig.moeDataCenter = MODataCenterData_center_0X;
   sdkConfig.appGroupID = @"group.com.XXXXXXXXXXXXXXXX";
   ```
3. **Notification Service Extension ターゲットを確認する**:
   * **プッシュ通知を有効にする**: 拡張ターゲットの Signing & Capabilities セクションで、必ず Push Notifications を有効にし、AppGroupId を追加してください。

     ![enable.png](https://mintcdn.com/moengage/jnaevUpPOwD04mEl/images/moengage_82ff4d.png?fit=max\&auto=format\&n=jnaevUpPOwD04mEl\&q=85\&s=54c3e655e26a7ba03c8ad3b31359a542)
   * **最小デプロイ iOS バージョンを揃える**: Notification Service Extension の最小デプロイ iOS バージョンが、メインアプリの iOS バージョンと一致していることを確認します。 ![support.png](https://mintcdn.com/moengage/Vec55CKt-wYQ1h5L/images/moengage_431d64.png?fit=max\&auto=format\&n=Vec55CKt-wYQ1h5L\&q=85\&s=c36f1c4da5df5ae2a3e5f0ea5b916b06)
4. MORichNotification フレームワークを Notification Service Extension ターゲットに統合します。
   ```objective-c Objective-C 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.m ファイルは次のようになります。
   ```objective-c Objective-C theme={null}
   #import "NotificationService.h"
   #import 
   @interface NotificationService ()
    
   @property (nonatomic, strong) void (^contentHandler)(UNNotificationContent *contentToDeliver);
   @property (nonatomic, strong) UNMutableNotificationContent *bestAttemptContent;
    
   @end
    
   @implementation NotificationService
    
   - (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {
       @try {
         	[MORichNotification setAppGroupID: @"group.com.XXXXXXXXXXXXXXXX"];
           self.contentHandler = contentHandler;
           self.bestAttemptContent = [request.content mutableCopy];
           [MORichNotification handleWithRichNotificationRequest:request withContentHandler:contentHandler];
       } @catch (NSException *exception) {
           NSLog(@"MoEngage : exception : %@",exception);
       }
   }
    
   /// Save the image to disk
   - (void)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.
       self.contentHandler(self.bestAttemptContent);
   }
   @end
   ```
6. **メインアプリターゲットの Build Phases を確認する**: メインアプリターゲットの Build Phases セクションで、Embed App Extensions / Embed Foundation Extensions セクションを見つけます。**Copy only when installing** オプションがオフになっていることを確認します。

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

   ![run.png](https://mintcdn.com/moengage/N1a7P_mcSpm-5bMa/images/moengage_569a68.png?fit=max\&auto=format\&n=N1a7P_mcSpm-5bMa\&q=85\&s=44379ecdb9a643302abd620bb735b1d4)

   ![build.png](https://mintcdn.com/moengage/t9nft78wsoLTI2Nx/images/moengage_29f224.png?fit=max\&auto=format\&n=t9nft78wsoLTI2Nx\&q=85\&s=06d507be5199e2e432eec62ade7496c8)


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