<!--
{
  "availability" : [
    "iOS: 18.1.0 -",
    "iPadOS: 18.1.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SecureElementCredential",
  "identifier" : "/documentation/SecureElementCredential/CredentialSession",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "SecureElementCredential"
    ],
    "preciseIdentifier" : "s:23SecureElementCredential0C7SessionC"
  },
  "title" : "CredentialSession"
}
-->

# CredentialSession

A class for performing actions on a credential stored in the Secure Element.

```
actor CredentialSession
```

## Overview

Create a credential session with the [`startSession()`](/documentation/SecureElementCredential/CredentialSession/startSession()) method. After you start a session, the session has three states:

- Management: In this default state, you can list, add, and delete credentials in the Secure Element.
- Wired: The wired state allows you to exchange data with a credential-corresponding entity (an *applet*) in the Secure Element.
- Card Emulation: In the card emulation state, your credential can communicate with a contactless card reader.

The framework provides SwiftUI and UIKit user interfaces for your app to display while using the wired and card emulation states.

You can read the current state at any time from the [`state`](/documentation/SecureElementCredential/CredentialSession/state-swift.property) property. The [`eventStream`](/documentation/SecureElementCredential/CredentialSession/eventStream) property provides an <doc://com.apple.documentation/documentation/Swift/AsyncStream> of events from both your own actions on credentials and outside sources like detecting an NFC reader’s RF field.

An app can have only one active session at a time. When your app no longer needs the credential session, call [`invalidate()`](/documentation/SecureElementCredential/CredentialSession/invalidate()). If your app goes into the background, the system automatically invalidates your session after a short delay. In wired mode, the system invalidates the session if it goes 15 seconds without performing a [`transceive(_:)`](/documentation/SecureElementCredential/CredentialSession/transceive(_:)) call.

### Use a session in an app extension

Certain methods in [`CredentialSession`](/documentation/SecureElementCredential/CredentialSession) are only appropriate for use in apps.
If you’re writing an app extension, such as for an identity service provider, use only the following methods:

- [`startSession()`](/documentation/SecureElementCredential/CredentialSession/startSession())
- [`listCredentials()`](/documentation/SecureElementCredential/CredentialSession/listCredentials())
- [`performWiredTransaction(using:over:instanceAID:)`](/documentation/SecureElementCredential/CredentialSession/performWiredTransaction(using:over:instanceAID:))
- [`transceive(_:)`](/documentation/SecureElementCredential/CredentialSession/transceive(_:))
- [`endWiredMode()`](/documentation/SecureElementCredential/CredentialSession/endWiredMode())
- [`invalidate()`](/documentation/SecureElementCredential/CredentialSession/invalidate())

## Topics

### Verifying eligibility

[`static var isEligible: Bool`](/documentation/SecureElementCredential/CredentialSession/isEligible)

A Boolean value that indicates whether the app or app extension is eligible to start a credential session.

### Accessing hardware information

[`var secureElementInfo: CredentialSession.SecureElementInfo`](/documentation/SecureElementCredential/CredentialSession/secureElementInfo-swift.property)

A property that provides information about the Secure Element hardware.

[`struct SecureElementInfo`](/documentation/SecureElementCredential/CredentialSession/SecureElementInfo-swift.struct)

A type that provides information about the Secure Element hardware.

### Managing the credential session life cycle

[`static func startSession() async throws -> CredentialSession`](/documentation/SecureElementCredential/CredentialSession/startSession())

Requests a session to view, manage, or use credentials in the Secure Element.

[`func invalidate() async throws`](/documentation/SecureElementCredential/CredentialSession/invalidate())

Inmediately invalidates a session.

### Accessing the session state

[`var state: CredentialSession.State`](/documentation/SecureElementCredential/CredentialSession/state-swift.property)

The current state of the session.

[`enum State`](/documentation/SecureElementCredential/CredentialSession/State-swift.enum)

An enumeration of the possible states of a card session.

### Accessing credentials

[`func listCredentials() async throws -> [CredentialSession.Credential]`](/documentation/SecureElementCredential/CredentialSession/listCredentials())

Retrieves a list of of credentials to which the app has access rights.

[`struct Credential`](/documentation/SecureElementCredential/CredentialSession/Credential)

Information about a credential that a credential session retrieves from the Secure Element.

### Acquiring exclusive foreground privileges

[`func acquirePresentmentAssertion() async throws -> CredentialSession.PresentmentIntentAssertion`](/documentation/SecureElementCredential/CredentialSession/acquirePresentmentAssertion())

Indicates that the app intends to present a credential to a contactless interface.

[`class PresentmentIntentAssertion`](/documentation/SecureElementCredential/CredentialSession/PresentmentIntentAssertion)

An object that signals your app’s intention to make exclusive use of the device’s contactless features.

### Handling session events

[`var eventStream: AsyncStream<CredentialSession.Event>`](/documentation/SecureElementCredential/CredentialSession/eventStream)

An asynchronous stream of session events.

[`enum Event`](/documentation/SecureElementCredential/CredentialSession/Event)

Events produced by a credential session, such as connectivity events and errors.

### Managing a credential

[`func provisionCredential(configurationUUID: UUID, name: String) async throws -> CredentialSession.Credential`](/documentation/SecureElementCredential/CredentialSession/provisionCredential(configurationUUID:name:))

Creates a credential in the Secure Element.

[`func deleteCredential(CredentialSession.Credential) async throws`](/documentation/SecureElementCredential/CredentialSession/deleteCredential(_:))

Deletes a credential on the Secure Element.

### Performing wired mode actions

[`func performWiredTransaction(using: CredentialSession.Credential, over: UIScene, instanceAID: Data) async throws`](/documentation/SecureElementCredential/CredentialSession/performWiredTransaction(using:over:instanceAID:))

Enters wired mode with user authentication.

[`func enterWiredMode(using: CredentialSession.Credential) async throws`](/documentation/SecureElementCredential/CredentialSession/enterWiredMode(using:))

Enters wired mode to perform maintenance operations with the given credential.

[`func transceive(Data) async throws -> Data`](/documentation/SecureElementCredential/CredentialSession/transceive(_:))

Send a wired command Application Protocol Data Unit (APDU) to the credential to complete a transaction or a card content management task.

[`func endWiredMode() async throws`](/documentation/SecureElementCredential/CredentialSession/endWiredMode())

Ends wired mode and returns to management state.

### Performing card emulation

[`func performCardEmulationTransactionWithCurrentCredential(over: UIScene, options: CredentialSession.CardEmulationOptions) async throws`](/documentation/SecureElementCredential/CredentialSession/performCardEmulationTransactionWithCurrentCredential(over:options:))

Activate the current credential in Wired mode to enter Card Emulation mode.

[`func performTransaction(using: CredentialSession.Credential, over: UIScene, options: CredentialSession.CardEmulationOptions) async throws`](/documentation/SecureElementCredential/CredentialSession/performTransaction(using:over:options:))

Prompts the user for authorization and then activate a credential for card emulation.

[`struct CardEmulationOptions`](/documentation/SecureElementCredential/CredentialSession/CardEmulationOptions)

Options for customizing card emulation behavior.

[`func endCardEmulation() async throws`](/documentation/SecureElementCredential/CredentialSession/endCardEmulation())

Ends card emulation and transitions the session to management state.

### Using SwiftUI

[`func configuration() async throws -> CredentialTransaction.Configuration`](/documentation/SecureElementCredential/CredentialSession/configuration())

Retrieves a transaction configuration related to this session.

[`class Configuration`](/documentation/SecureElementCredential/CredentialTransaction/Configuration)

An object that provides configuration information for a transaction that the client intends to perform.

### Handling errors

[`enum ErrorCode`](/documentation/SecureElementCredential/CredentialSession/ErrorCode)

An error encountered by a credential session.

### Infrequently-used functionality

[`init()`](/documentation/SecureElementCredential/CredentialSession/init())

Creates an empty credential session.

### Structures

[`struct ConnectivityEvent`](/documentation/SecureElementCredential/CredentialSession/ConnectivityEvent)

An event that a credential receives during card emulation.

### Enumerations

[`enum NFCFieldInformation`](/documentation/SecureElementCredential/CredentialSession/NFCFieldInformation)

The state of an NFC RF field.

## Relationships

### Conforms To

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

[`Equatable`](/documentation/Swift/Equatable)

[`Sendable`](/documentation/Swift/Sendable)

[`Actor`](/documentation/Swift/Actor)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)