> 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/tokenization/es/integrar-id-and-v-en-la-app/integracion-con-apple-pay.md). Agents can also search and read this documentation through its [MCP server](https://docs.payments.thalescloud.io/~gitbook/mcp).

# Integración con Apple Pay

Usa esta guía para admitir ID\&V en la aplicación cuando un usuario final aprovisiona una tarjeta en Apple Pay.

Configuras los parámetros de redirección en tu TSP de la red de pago. Apple Pay los usa para abrir la aplicación del emisor.

### Configura tu TSP de la red de pago

Configura estos parámetros de redirección en tu TSP de la red de pago:

* **contactName**: Nombre para mostrar del emisor que se muestra al usuario final.
* **bank\_app**: Nombre de la aplicación del emisor usado para ID\&V en la aplicación.
* **appLaunchURL**: Esquema de URL personalizado que abre la aplicación del emisor.
* **associatedStoreIdentifiers**: Identificador(es) de App Store. Se usa cuando la aplicación del emisor no está instalada.
* **associatedApplicationIdentifiers**: Identificador(es) de la aplicación. Normalmente el ID de equipo de Apple y el ID del paquete de la app.

### Implementa el controlador de la aplicación del emisor

#### Configura un esquema de URL personalizado en Xcode

En Xcode, ve a **Configuración del proyecto** > **Objetivos** > tu app.

Abre la `pestaña Info.` Establece

* identificador `en un identificador único. Usa el ID del paquete de la app.` Esquemas de URL
* identificador `a tu esquema personalizado.` Rol
* identificador `Editor` a `Configura un esquema de URL personalizado en Xcode.`.

<figure><img src="https://content.gitbook.com/content/W6dljaTEEzefPQILRFB7/blobs/JcUv1dlsfJkQk0BVWonZ/ide%20configuration%20inapp%20auth.png" alt="Xcode Info tab showing URL Types configuration for a custom URL scheme."><figcaption><p>Configura un esquema de URL personalizado en Xcode.</p></figcaption></figure>

#### Gestiona el deep link y valida al llamante

Cuando la aplicación de billetera digital redirige al usuario final a la aplicación del emisor, la aplicación del emisor debe validar la solicitud antes de iniciar ID\&V.

Apple Pay agrega parámetros de consulta que identifican el pase. Úsalos con [`PKPassLibrary.pass(withPassTypeIdentifier:serialNumber:)`](https://developer.apple.com/documentation/passkit/pkpasslibrary/1617104-pass) para confirmar que el pase existe en el dispositivo.

{% hint style="warning" %}
Valida el deep link antes de autenticar al usuario final o activar la tarjeta digital.

Trata los parámetros faltantes o inesperados como un intento de ID\&V fallido.
{% endhint %}

Ejemplo de deep link:

`myscheme://mypath?passTypeIdentifier=paymentpass.com.apple&serialNumber=123&action=verify`

Ejemplo en Swift:

{% code overflow="wrap" %}

```swift
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
    guard let components = URLComponents(url: url, resolvingAgainstBaseURL: true) else {
        // gestionar el error, p. ej., registrar
        return false
    }
    
    guard let queryItems = components.queryItems else {
        // gestionar el error, p. ej., registrar
        return false
    }

    // ejemplo de comprobación de los elementos de la consulta
    let containsPassTypeIdentifier = queryItems.contains(where: { $0.name == "passTypeIdentifier" && $0.value == "paymentpass.com.apple" })
    let containsSerialNumber = queryItems.contains(where: { $0.name == "serialNumber" })
    let containsAction = queryItems.contains(where: { $0.name == "action" })
    let validated = containsPassTypeIdentifier && containsSerialNumber && containsAction

    if validated {
        // continuar con la activación
    } else {
        // gestionar el error, p. ej., mostrar una interfaz de error
    }
    
    return validated
}
```

{% endcode %}

Para más detalles sobre los esquemas de URL personalizados, consulta la [documentación de Apple](https://developer.apple.com/documentation/xcode/defining-a-custom-url-scheme-for-your-app).

### Identifica la tarjeta digital

Usa estos parámetros de la API PassKit de iOS para identificar la tarjeta digital que se va a activar:

* passTypeIdentifier
* serialNumber

Estos parámetros identifican el `pase` que se va a activar.

El siguiente código de ejemplo en Swift describe cómo usar estos datos para identificar el `pase`.

{% hint style="warning" %}
Este código de ejemplo se proporciona tal cual.

Usa las especificaciones más recientes de Apple.
{% endhint %}

{% code overflow="wrap" %}

```swift
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
    guard let components = URLComponents(url: url, resolvingAgainstBaseURL: true) else {
        // gestionar el error, p. ej., registrar
        return false
    }
    
    guard let queryItems = components.queryItems else {
        // gestionar el error, p. ej., registrar
        return false
    }

    var passTypeIdentifier: String? = nil
    var serialNumber: String? = nil
    var action: String? = nil

    for queryItem in queryItems {
        if queryItem.name == "passTypeIdentifier" {
            passTypeIdentifier = queryItem.value
        } else if queryItem.name == "serialNumber" {
            serialNumber = queryItem.value
        } else if queryItem.name == "action" {
            action = queryItem.value
        }
    }

    if let passTypeIdentifier = passTypeIdentifier,
        let serialNumber = serialNumber,
        action != nil {
        let library = PKPassLibrary()
        if let pendingPass = library.pass(withPassTypeIdentifier: passTypeIdentifier, serialNumber: serialNumber) {
            if #available(iOS 13.4, *) {
                if let primaryAccountNumberSuffix = pendingPass.secureElementPass?.primaryAccountNumberSuffix,
                    let deviceAccountIdentifier = pendingPass.secureElementPass?.deviceAccountIdentifier {
                    // continuar con la activación mediante el SDK
                }
            } else {
                if let primaryAccountNumberSuffix = pendingPass.paymentPass?.primaryAccountNumberSuffix,
                    let deviceAccountIdentifier = pendingPass.paymentPass?.deviceAccountIdentifier {
                    // continuar con la activación mediante el SDK
                }
            }
        }
        return true
    } else {
        // gestionar el error, p. ej., mostrar una interfaz de error
        return false
    }
}
```

{% endcode %}

{% hint style="info" %}
El `deviceAccountIdentifier` corresponde a `digitalCardId` en D1 y a `virtualCardId` en TSH.

Úsalo para activar la tarjeta digital.
{% endhint %}

{% hint style="info" %}
El `primaryAccountNumberSuffix` son los últimos cuatro dígitos del PAN que se tokenizó.

Úsalo para recuperar y mostrar al usuario final la imagen de la tarjeta correcta durante ID\&V.
{% endhint %}


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.payments.thalescloud.io/tokenization/es/integrar-id-and-v-en-la-app/integracion-con-apple-pay.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
