> For the complete documentation index, see [llms.txt](https://docs.payments.thalescloud.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.payments.thalescloud.io/nfc-wallet-sdk-ios/ja/get-started/configuration/4.-push-notifications/handle-push-notifications.md).

# プッシュ通知を処理する

NFC Wallet はプッシュ通知を使用してあなたに通知します **デジタルウォレットアプリケーション**。通知は NFC Wallet のバックエンドによって送信されます。

{% hint style="info" %}
NFC Wallet のプッシュ通知の処理は、次をサポートするために必要です **LCM**、トランザクション通知、およびデジタルカードがイシュアによって直接有効化されるカード登録フロー。
{% endhint %}

### を使用して通知をルーティングします `sender`

読み取り `userInfo["sender"]` し、通知を適切なハンドラーに振り分けます:

* `CPS`: デジタルカード操作 (**LCM**)
* `TNS`: トランザクション通知
* `MG`: によってトリガーされる支払いキー補充 **TSP**

```swift
func application(
    _ application: UIApplication,
    didReceiveRemoteNotification userInfo: [AnyHashable : Any],
    fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void
) {
    let sender = userInfo["sender"] as? String

    Task {
        do {
            switch sender {
            case "CPS":
                // デジタルカード操作 (LCM)。
                // SDK の通知ハンドラーを呼び出します。API リファレンスの `NotificationService` を参照してください。
                break

            case "TNS":
                // トランザクション通知。
                // トランザクション履歴を更新します。API リファレンスの `TransactionHistoryService` を参照してください。
                break

            case "MG":
                // TSP によってトリガーされたキー補充。
                // 補充をトリガーします。API リファレンスの `ReplenishmentService` を参照してください。
                break

            default:
                // SDK 以外の通知。
                break
            }

            completionHandler(.newData)
        } catch {
            completionHandler(.failed)
        }
    }
}
```

### CPS 通知（デジタルカード操作）を処理する

転送する **CPS** プッシュ通知を SDK に `NotificationService.processNotification()`.

<pre class="language-swift"><code class="lang-swift">let notification = NotificationService()
<strong>do {
</strong>    try await notification.processNotification(forUserInfo: userInfo)
} catch {
    // エラーを表示する
}
</code></pre>

NFC Wallet SDK はプッシュを処理し、NFC Wallet のバックエンドと連携します。

その後、SDK は以下を通じて通知イベントを発行できます `NotificationService.notificationEventStream`。これらのイベントを使用してデジタルカード操作を追跡します。

サポートされるイベント:

* `unsupportedPushContent`: プッシュペイロードが SDK でサポートされていない場合にトリガーされます。
* `completed`: 処理が正常に完了したときにトリガーされます（たとえば、カードプロファイルと支払いキーのプロビジョニング後）。
* `serverMessage`: バックエンドが指示を返したときにトリガーされます。SDK は `serverMessage` オブジェクトと `tokenizedId`.

#### サーバーメッセージ

受信したら `serverMessage`を提供します。 `serverMessage` オブジェクトを解析して、バックエンドがどの操作を要求したのかを判断します。

特に:

* `requestInstallCard`: カードのインストール要求。
* `requestResumeCard`: カードを一時停止からアクティブに移す要求。
* `requestSuspendCard`: カードをアクティブから一時停止に移す要求。
* `requestDeleteCard`: カードの削除要求。

### TNS 通知（トランザクション）を処理する

トランザクション通知は、完了した支払いトランザクションの詳細を提供します。 `TransactionHistoryService` を使用してトランザクション記録を取得します。

プッシュ通知を通じて、 **デジタルウォレットアプリケーション** は通知の `userInfo` パラメータ経由で次の情報を取得します:

* `userInfo["sender"]`: `TNS`.
* `userInfo["action"]`: `TNS:PaymentTransactionNotification`.
* `userInfo["digitalCardId"]`: デジタルカード識別子。 `TransactionHistoryService.records(forDigitalCardID:)`.
* `userInfo["transactionRecordType"]`: コバッジカードの場合のみ存在します。 `TransactionHistoryService.records(forDigitalCardID:transactionRecordType:)` に渡して、関連する記録（プライマリまたは補助）のみを取得します。

<pre class="language-swift"><code class="lang-swift">let action = userInfo["action"] as? String
let cardId = userInfo["digitalCardId"] as? String
let recordType = userInfo["transactionRecordType"] as? String

// 期待される action と card id の存在を確認します。
guard "TNS:PaymentTransactionNotification" == action, let cardId = cardId else {
    // エラーを表示する
}

let historyService = TransactionHistoryService()
do {       
<strong>    let records = try await historyService.records(forDigitalCardID: cardId, transactionRecordType: recodType)
</strong>} catch {
    // エラーを表示する
}
</code></pre>

### MG通知を処理する（補充）

この **TSP** は支払いキーの補充を要求できます。 `ReplenishmentService` を使用してキーを補充します。

プッシュ通知を通じて、 **デジタルウォレットアプリケーション** は通知の `userInfo` パラメータ経由で次の情報を取得します:

* `userInfo["sender"]`: `MG`.
* `userInfo["action"]`: `MG:ReplenishmentNeededNotification`.
* `userInfo["digitalCardId"]`: デジタルカード識別子。 `ReplenishmentService.replenish(digitalCardID:isForced:)`.

<pre class="language-swift"><code class="lang-swift">let action = userInfo["action"] as? String
let cardId = userInfo["digitalCardId"] as? String

// 期待される action と card id の存在を確認します。
guard "MG:ReplenishmentNeededNotification" == action, let cardId = cardId else {
    // エラーを表示する
}

let replenishmentService = ReplenishmentService()
do {       
<strong>    try await replenishmentService.replenish(digitalCardID: cardId, isForced: true)
</strong>} catch {
    // エラーを表示する
}
</code></pre>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.payments.thalescloud.io/nfc-wallet-sdk-ios/ja/get-started/configuration/4.-push-notifications/handle-push-notifications.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
