<!--
{
  "availability" : [
    "iOS: 9.0.0 -",
    "iPadOS: 9.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.10.0 -",
    "tvOS: 11.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 4.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CryptoTokenKit",
  "identifier" : "/documentation/CryptoTokenKit/TKSmartCard",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "CryptoTokenKit"
    ],
    "preciseIdentifier" : "c:objc(cs)TKSmartCard"
  },
  "title" : "TKSmartCard"
}
-->

# TKSmartCard

A representation of a smart card.

```
class TKSmartCard
```

## Overview

This class provides an interface for managing sessions with a smart card, transmitting requests, and facilitating user interaction.

You can create a [`TKSmartCard`](/documentation/CryptoTokenKit/TKSmartCard) object when a smart card is inserted into a slot, by calling the [`makeSmartCard()`](/documentation/CryptoTokenKit/TKSmartCardSlot/makeSmartCard()) method on the corresponding [`TKSmartCardSlot`](/documentation/CryptoTokenKit/TKSmartCardSlot) object. To start communicating with the smart card, call the [`beginSession(reply:)`](/documentation/CryptoTokenKit/TKSmartCard/beginSession(reply:)) method on the [`TKSmartCard`](/documentation/CryptoTokenKit/TKSmartCard) object. Once an exclusive session has been established, you transmit data using the [`transmit(_:reply:)`](/documentation/CryptoTokenKit/TKSmartCard/transmit(_:reply:)) method. After you’ve finished communicating with a smart card, you call the [`endSession()`](/documentation/CryptoTokenKit/TKSmartCard/endSession()) method.

If the smart card is physically removed from its slot, the session object becomes invalid, and any further calls to [`transmit(_:reply:)`](/documentation/CryptoTokenKit/TKSmartCard/transmit(_:reply:)) will return an error. You can use Key-Value Observing on the [`isValid`](/documentation/CryptoTokenKit/TKSmartCard/isValid) property to be notified when a smart card is invalidated, due to being removed from the slot or another reason.

## Topics

### Configuring the Smart Card

[`slot`](/documentation/CryptoTokenKit/TKSmartCard/slot)

The slot in which the Smart Card is inserted.

[`isValid`](/documentation/CryptoTokenKit/TKSmartCard/isValid)

Whether the Smart Card is valid and accessible from its slot.

[`isSensitive`](/documentation/CryptoTokenKit/TKSmartCard/isSensitive)

Whether sessions established for the Smart Card should be considered sensitive. <doc://com.apple.documentation/documentation/Swift/false> by default.

[`context`](/documentation/CryptoTokenKit/TKSmartCard/context)

User-specified information. This property is automatically set to `nil` if the Smart Card is removed or another `TKSmartCard` object begins a session.

### Setting the Communication Protocol

[`allowedProtocols`](/documentation/CryptoTokenKit/TKSmartCard/allowedProtocols)

The protocols allowed for communication with the Smart Card. [`any`](/documentation/CryptoTokenKit/TKSmartCardProtocol/any) by default.

[`currentProtocol`](/documentation/CryptoTokenKit/TKSmartCard/currentProtocol)

The protocol used for communication with the Smart Card. Returns [`TKSmartCardProtocolNone`](/documentation/CryptoTokenKit/TKSmartCardProtocol/TKSmartCardProtocolNone) if no session is currently established.

[`TKSmartCardProtocol`](/documentation/CryptoTokenKit/TKSmartCardProtocol)

Smart Card transmission protocols.

### Communicating with the Smart Card

[`beginSession(reply:)`](/documentation/CryptoTokenKit/TKSmartCard/beginSession(reply:))

Begins a session with the Smart Card.

[`transmit(_:reply:)`](/documentation/CryptoTokenKit/TKSmartCard/transmit(_:reply:))

Transmits data in Application Protocol Data Unit (APDU) format to the Smart Card.

[`endSession()`](/documentation/CryptoTokenKit/TKSmartCard/endSession())

Completes any pending transmissions and ends the session to the Smart Card.

### Managing User Interaction

[`userInteractionForSecurePINVerification(_:apdu:pinByteOffset:)`](/documentation/CryptoTokenKit/TKSmartCard/userInteractionForSecurePINVerification(_:apdu:pinByteOffset:))

Creates and returns a new user interaction object for secure PIN verification using the Smart Card reader facilities.

[`userInteractionForSecurePINChange(_:apdu:currentPINByteOffset:newPINByteOffset:)`](/documentation/CryptoTokenKit/TKSmartCard/userInteractionForSecurePINChange(_:apdu:currentPINByteOffset:newPINByteOffset:))

Creates a new user interaction object for secure PIN change using the smart card reader facilities (typically a HW keypad).

[`TKSmartCardPINFormat`](/documentation/CryptoTokenKit/TKSmartCardPINFormat)

The formatting properties for a PIN, such as character encoding and length constraints.

[`TKSmartCardUserInteraction`](/documentation/CryptoTokenKit/TKSmartCardUserInteraction)

The base class for encapsulating user interaction with a Smart Card reader.

[`TKSmartCardUserInteractionForPINOperation`](/documentation/CryptoTokenKit/TKSmartCardUserInteractionForPINOperation)

A representation of user interaction for secure PIN operations on a Smart Card reader.

[`TKSmartCardUserInteractionForSecurePINChange`](/documentation/CryptoTokenKit/TKSmartCardUserInteractionForSecurePINChange)

A representation of the user interaction for secure PIN change operations on a Smart Card reader.

[`TKSmartCardUserInteractionForSecurePINVerification`](/documentation/CryptoTokenKit/TKSmartCardUserInteractionForSecurePINVerification)

A representation of the user interaction for secure PIN change verification on a Smart Card reader.

### Configuring APDU Behavior

[`cla`](/documentation/CryptoTokenKit/TKSmartCard/cla)

The CLA byte used for APDU transmission. `0x00` by default.

[`useExtendedLength`](/documentation/CryptoTokenKit/TKSmartCard/useExtendedLength)

Whether to use extended length APDU.

[`useCommandChaining`](/documentation/CryptoTokenKit/TKSmartCard/useCommandChaining)

Whether to use command chaining of APDU with a data field longer than 255 bytes.

### Transmitting Data

[`send(ins:p1:p2:data:le:reply:)`](/documentation/CryptoTokenKit/TKSmartCard/send(ins:p1:p2:data:le:reply:))

Asynchronously transmits an APDU command to the card, returning the response in a completion handler.

[`withSession(_:)`](/documentation/CryptoTokenKit/TKSmartCard/withSession(_:))

Synchronously begins a session, executes the given closure, and ends the session.

[`sendIns:p1:p2:data:le:reply:`](/documentation/CryptoTokenKit/TKSmartCard/sendIns:p1:p2:data:le:reply:)

Asynchronously transmits an APDU command to the card, returning the response in a completion handler.

[`sendIns:p1:p2:data:le:sw:error:`](/documentation/CryptoTokenKit/TKSmartCard/sendIns:p1:p2:data:le:sw:error:)

Synchronously transmits an APDU command to the card and returns the response.

[`inSessionWithError:executeBlock:`](/documentation/CryptoTokenKit/TKSmartCard/inSessionWithError:executeBlock:)

Synchronously begins a session, executes the given block, and ends the session.



---

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)