> 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-tokens.md).

# プッシュトークンの処理

## プッシュ通知に登録する

### APNs と FCM を登録する

以下の例は、一般的な iOS の設定例を示しています：

* Firebase を設定する。
* 通知の許可をリクエストする。
* APNs に登録する。
* APNs トークンを Firebase Messaging に提供する。

{% hint style="info" %}
FCM の構成（Firebase プロジェクトの設定、エンタイトルメント、APNs キーなど）は本ガイドの範囲外です。

設定の詳細については、次を参照してください [FCM 入門](https://firebase.google.com/docs/cloud-messaging), [FCM のアーキテクチャ概要](https://firebase.google.com/docs/cloud-messaging/fcm-architecture) および [FCM メッセージについて](https://firebase.google.com/docs/cloud-messaging/concept-options).
{% endhint %}

{% code title="APNs と FCM を登録する" %}

```swift
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        
        // ...
        
        // Firebase ライブラリを使用して API を構成する
        FirebaseApp.configure()

        // ユーザー通知を登録する 
        let settings: UIUserNotificationSettings = UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
        application.registerUserNotificationSettings(settings)
      
        // Firebase 登録 
        Messaging.messaging().delegate = self
        // リモート通知に登録する 
        application.registerForRemoteNotifications()
        return true
}
```

{% endcode %}

## NFC Wallet にプッシュトークンを更新する

プッシュトークンは変更されることがあります（例：アプリ再インストール後や Firebase がトークンを更新したとき）。このような場合、あなたのデジタルウォレットアプリケーションは NotificationService.updatePushToken を呼び出して NFC Wallet SDK に通知する必要があります。 `NotificationService.updatePushToken`.

{% hint style="info" %}
NFC Wallet SDK はトークンが変更されていないことを検出すると、NFC Wallet バックエンドへの不要な呼び出しを回避します。
{% endhint %}

```swift
func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) {
    guard let fcmToken else { return }
      do {
          // プッシュトークンを更新する 
          let notificationService = try NotificationService()
          try await notificationService.updatePushToken(token)
        } catch {
          // エラーハンドリング
        }
}
```


---

# 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-tokens.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.
