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

# UMP連携

> GDPR/CCPA準拠のためのGoogle UMP連携

## 概要

UMP（User Messaging Platform）SDKは、GDPR（一般データ保護規則）およびCCPA（カリフォルニア消費者プライバシー法）準拠のために、パーソナライズド広告に対するユーザーの同意を管理します。

<Note>
  UMP連携には`adrop-ads-backfill`モジュールが必要です。[はじめに](/ja/sdk/ios/overview)のインストールガイドを先に完了してください。
</Note>

***

## 基本的な使い方

Adrop初期化後にConsent Managerを使用してユーザーの同意を要求します。

<CodeGroup>
  ```swift Swift theme={null}
  import AdropAds

  class ViewController: UIViewController {

      override func viewDidLoad() {
          super.viewDidLoad()

          // Adrop.initialize()の後に呼び出し
          Adrop.consentManager?.requestConsentInfoUpdate(from: self) { result in
              if let error = result.error {
                  print("同意エラー: \(error)")
              }
          }
      }
  }
  ```

  ```objc Objective-C theme={null}
  @import AdropAds;

  @implementation ViewController

  - (void)viewDidLoad {
      [super viewDidLoad];

      // Adrop.initialize()の後に呼び出し
      if (Adrop.consentManager != nil) {
          [Adrop.consentManager requestConsentInfoUpdateFrom:self completion:^(AdropConsentResult *result) {
              if (result.error != nil) {
                  NSLog(@"同意エラー: %@", result.error);
              }
          }];
      }
  }

  @end
  ```
</CodeGroup>

***

## 同意結果

`requestConsentInfoUpdate`のコールバックは、以下のプロパティを持つ`AdropConsentResult`オブジェクトを返します：

| プロパティ                    | 型                    | 説明                   |
| ------------------------ | -------------------- | -------------------- |
| `status`                 | `AdropConsentStatus` | 現在の同意ステータス           |
| `canRequestAds`          | `Bool`               | 広告リクエストが可能かどうか       |
| `canShowPersonalizedAds` | `Bool`               | パーソナライズド広告の表示が可能かどうか |
| `error`                  | `Error?`             | リクエスト失敗時のエラー         |

<CodeGroup>
  ```swift Swift theme={null}
  Adrop.consentManager?.requestConsentInfoUpdate(from: self) { result in
      print("Status: \(result.status)")
      print("Can request ads: \(result.canRequestAds)")
      print("Can show personalized ads: \(result.canShowPersonalizedAds)")

      if let error = result.error {
          print("Error: \(error)")
      }
  }
  ```

  ```objc Objective-C theme={null}
  [Adrop.consentManager requestConsentInfoUpdateFrom:self completion:^(AdropConsentResult *result) {
      NSLog(@"Status: %ld", (long)result.status);
      NSLog(@"Can request ads: %d", result.canRequestAds);
      NSLog(@"Can show personalized ads: %d", result.canShowPersonalizedAds);

      if (result.error != nil) {
          NSLog(@"Error: %@", result.error);
      }
  }];
  ```
</CodeGroup>

***

## 同意ステータス

Consent Managerは次のステータスのいずれかを返します：

| ステータス         | 説明                  |
| ------------- | ------------------- |
| `unknown`     | 同意ステータスがまだ決定されていない  |
| `required`    | 同意が必要（ポップアップが表示される） |
| `notRequired` | 同意は不要（非GDPR地域）      |
| `obtained`    | すでに同意を取得済み          |

***

## デバッグ設定（テストモード）

開発中にGDPR/CCPA同意フローをテストしてください：

<CodeGroup>
  ```swift Swift theme={null}
  import AdropAds

  #if DEBUG
  // 同意リクエスト前にデバッグ地域を設定
  Adrop.consentManager?.setDebugSettings(
      testDeviceIdentifiers: ["YOUR_DEVICE_IDENTIFIER"],  // Xcodeコンソールで確認
      geography: .EEA  // GDPRテスト
  )

  // テスト用に同意状態をリセット
  Adrop.consentManager?.reset()
  #endif
  ```

  ```objc Objective-C theme={null}
  @import AdropAds;

  #ifdef DEBUG
  // 同意リクエスト前にデバッグ地域を設定
  [Adrop.consentManager setDebugSettingsWithTestDeviceIdentifiers:@[@"YOUR_DEVICE_IDENTIFIER"]
                                                        geography:AdropConsentDebugGeographyEEA];

  // テスト用に同意状態をリセット
  [Adrop.consentManager reset];
  #endif
  ```
</CodeGroup>

### デバッグ地域

| 地域                 | 説明                 |
| ------------------ | ------------------ |
| `disabled`         | 実際のデバイス位置を使用       |
| `EEA`              | GDPRテスト（欧州経済領域）    |
| `regulatedUSState` | CCPAテスト（カリフォルニアなど） |
| `other`            | 非規制地域テスト           |

<Warning>
  デバッグ設定は開発中のみ使用してください。本番リリース前に削除または無効化してください。
</Warning>

***

## 追加メソッド

| メソッド                 | 戻り値                  | 説明                          |
| -------------------- | -------------------- | --------------------------- |
| `getConsentStatus()` | `AdropConsentStatus` | 現在の同意状態を返します                |
| `canRequestAds()`    | `Bool`               | 同意状態に基づいて広告リクエスト可能かどうかを返します |
| `reset()`            | `Void`               | 同意情報をリセットします                |

```swift theme={null}
// 同意状態を個別に確認
if let status = Adrop.consentManager?.getConsentStatus() {
    switch status {
    case .obtained:
        print("同意完了")
    case .required:
        print("同意必要")
    case .notRequired:
        print("同意不要")
    case .unknown:
        print("同意状態不明")
    }
}

// 広告リクエスト可能か確認
if Adrop.consentManager?.canRequestAds() == true {
    // 広告をロード
}

// 同意情報をリセット（テスト用）
Adrop.consentManager?.reset()
```

***

## ベストプラクティス

<CardGroup cols={2}>
  <Card title="早期リクエスト" icon="clock">
    SDK初期化直後、アプリライフサイクルの早い段階で同意を要求してください。
  </Card>

  <Card title="エラー処理" icon="triangle-exclamation">
    同意エラーを適切に処理し、フォールバック動作を提供してください。
  </Card>

  <Card title="全シナリオテスト" icon="vial">
    リリース前にデバッグ設定を使用してすべての同意シナリオをテストしてください。
  </Card>

  <Card title="ユーザー選択の尊重" icon="user-check">
    同意を得たり拒否された後は、ユーザーの選択を尊重し、繰り返し要求しないでください。
  </Card>
</CardGroup>

***

## 関連ドキュメント

<CardGroup cols={2}>
  <Card title="ターゲティング" icon="bullseye" href="/ja/sdk/ios/targeting">
    ユーザーおよびコンテキストターゲティング設定
  </Card>

  <Card title="はじめに" icon="rocket" href="/ja/sdk/ios/overview">
    SDKインストールおよび設定ガイド
  </Card>

  <Card title="リファレンス" icon="book" href="/ja/sdk/ios/reference">
    クラス、デリゲート、エラーコード
  </Card>
</CardGroup>
