---
title: iOS
description: Integra la jornada Human Token en tu aplicación iOS usando ASWebAuthenticationSession — nativo, seguro y sin necesidad de WebView.
canonical: https://developer.unico.io/es/human-token/integrations/app/ios/link-integration
locale: es
generated_by: markdown-export
---

# iOS

Integra la jornada Human Token en tu aplicación iOS usando ASWebAuthenticationSession.

`ASWebAuthenticationSession` inicia la jornada Human Token en un navegador administrado por el sistema. Cuando la jornada finaliza, la sesión regresa a tu aplicación a través del esquema de URL registrado.

### Requisitos previos

- iOS 13 o posterior
- Xcode 14+
- Framework `AuthenticationServices` (integrado)
- Un esquema de URL único para tu aplicación (por ejemplo, `myapp`)

### Paso 1: Definir tu esquema de URL

Elige un esquema único (por ejemplo, `myapp`). Se usa como `callbackUri` al crear el proceso:

```
callbackUri: myapp://callback
```

### Paso 2: Crear el proveedor de contexto de presentación

```swift
import AuthenticationServices
import UIKit

class UnicoAuthenticationController: NSObject, ASWebAuthenticationPresentationContextProviding {
    func presentationAnchor(for session: ASWebAuthenticationSession) -> ASPresentationAnchor {
        guard let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
              let window = windowScene.windows.first else {
            return ASPresentationAnchor()
        }
        return window
    }
}
```

### Paso 3: Crear el administrador de sesión

```swift
import AuthenticationServices

class AuthenticationSessionManager {
    static let shared = AuthenticationSessionManager()
    private var session: ASWebAuthenticationSession?
    private let contextProvider = UnicoAuthenticationController()

    func start(url: URL, completion: @escaping (String?) -> Void) {
        let newSession = ASWebAuthenticationSession(
            url: url,
            callbackURLScheme: "myapp"
        ) { callbackURL, error in
            self.session = nil
            if let callbackURL = callbackURL {
                let components = URLComponents(url: callbackURL, resolvingAgainstBaseURL: false)
                let processId = components?.queryItems?.first(where: { $0.name == "id" })?.value
                completion(processId)
            } else {
                completion(nil)
            }
        }
        newSession.presentationContextProvider = contextProvider
        newSession.prefersEphemeralWebBrowserSession = true
        newSession.start()
        session = newSession
    }
}
```

### Paso 4: Iniciar la jornada

```swift
guard let url = URL(string: processLink) else { return }

AuthenticationSessionManager.shared.start(url: url) { processId in
    if let processId = processId {
        // Journey completed — send processId to your backend via Get Process
    } else {
        // User canceled the session
    }
}
```

> **Información:** El parámetro `callbackURLScheme` solo acepta el nombre del esquema (`myapp`), sin `://`.

### Resumen de archivos

| Archivo | Propósito |
|---|---|
| `UnicoAuthenticationController.swift` | Proveedor de contexto de presentación |
| Administrador de sesión (tu vista o servicio) | Ciclo de vida de `ASWebAuthenticationSession` |