---
title: Integração por link iOS
description: Integre a jornada Human Token no seu aplicativo iOS usando ASWebAuthenticationSession — nativo, seguro e sem necessidade de WebView.
canonical: https://developer.unico.io/pt-BR/human-token/integrations/app/ios/link-integration
locale: pt-BR
generated_by: markdown-export
---

# Integração por link iOS

Integre a jornada Human Token no seu aplicativo iOS usando ASWebAuthenticationSession.

`ASWebAuthenticationSession` inicia a jornada Human Token em um navegador gerenciado pelo sistema. Quando a jornada termina, a sessão retorna ao seu aplicativo pelo esquema de URL registrado.

> **Dica: Prefira o SDK Lite**
>
> O [SDK Lite iOS](/human-token/integrations/app/ios/sdk-lite) abre a captura de forma nativa com o `webAppToken` e é o caminho preferencial no iOS. Use esta página, que abre o `link` da jornada, quando o SDK Lite não servir para o seu app.

### Pré-requisitos

- iOS 13 ou posterior
- Xcode 14+
- Framework `AuthenticationServices` (integrado)
- Um esquema de URL exclusivo para o seu aplicativo (ex.: `myapp`)

### Passo 1: Definir o esquema de URL

Escolha um esquema exclusivo (ex.: `myapp`). Ele é usado como `callbackUri` ao criar o processo:

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

### Passo 2: Criar o provedor de contexto de apresentação

```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
    }
}
```

### Passo 3: Criar o gerenciador de sessão

```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
    }
}
```

### Passo 4: Iniciar a 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
    }
}
```

> **Informação:** O parâmetro `callbackURLScheme` aceita apenas o nome do esquema (`myapp`), sem `://`.

### Resumo dos arquivos

| Arquivo | Finalidade |
|---|---|
| `UnicoAuthenticationController.swift` | Provedor de contexto de apresentação |
| Gerenciador de sessão (sua view ou serviço) | Ciclo de vida do `ASWebAuthenticationSession` |