> 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 がトークンを更新したときなど）。この場合、デジタルウォレットアプリケーションは、次を呼び出して 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, 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-tokens.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.
