> 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/es/get-started/configuration/4.-push-notifications/handle-push-tokens.md).

# Gestionar tokens push

## Regístrese para notificaciones push

### Registrar APNs y FCM

El ejemplo a continuación muestra una configuración típica de iOS:

* Configurar Firebase.
* Solicitar permisos de notificación.
* Registrarse en APNs.
* Proporcionar el token de APNs a Firebase Messaging.

{% hint style="info" %}
La configuración de FCM (configuración del proyecto de Firebase, permisos, clave de APNs, etc.) está fuera del alcance de esta guía.

Para detalles de configuración, consulte [Introducción a FCM](https://firebase.google.com/docs/cloud-messaging), [Descripción arquitectónica de FCM](https://firebase.google.com/docs/cloud-messaging/fcm-architecture) y [Acerca de los mensajes de FCM](https://firebase.google.com/docs/cloud-messaging/concept-options).
{% endhint %}

{% code title="Registrar APNs y FCM" %}

```swift
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        
        // ...
        
        // Use la biblioteca de Firebase para configurar las API
        FirebaseApp.configure()

        // Registrar notificaciones de usuario 
        let settings: UIUserNotificationSettings = UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
        application.registerUserNotificationSettings(settings)
      
        // Registro de Firebase 
        Messaging.messaging().delegate = self
        // Registrarse para Notificaciones Remotas 
        application.registerForRemoteNotifications()
        return true
}
```

{% endcode %}

## Actualizar el token push en NFC Wallet

El token push puede cambiar (por ejemplo, después de reinstalar la aplicación o cuando Firebase actualiza el token). Cuando esto sucede, su aplicación de billetera digital debe notificar al SDK de NFC Wallet llamando a `NotificationService.updatePushToken`.

{% hint style="info" %}
El SDK de NFC Wallet detecta cuando el token no ha cambiado y evita llamadas innecesarias al backend de NFC Wallet.
{% endhint %}

```swift
func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) {
    guard let fcmToken else { return }
      do {
          // actualizar token push 
          let notificationService = try NotificationService()
          try await notificationService.updatePushToken(token)
        } catch {
          // manejo de errores
        }
}
```


---

# 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/es/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.
