> 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 %}

### 通知を次でルーティングします `送信者`

読み取り `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

// 期待されるアクションとカード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

// 期待されるアクションとカード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:

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

The question should be specific, self-contained, and written in natural language.
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.
