# NFC Tags (/in-store/integration/nfc_tags)

<div className="bg-background relative h-auto w-full overflow-hidden rounded-lg border mt-8">
  
<FlickeringGrid squareSize={4} gridGap={6} maxOpacity={0.1} flickerChance={0.1} height={600} width={2000} />

  
<NfcTagSessionDiagram />

</div>

## Before you start [#before-you-start]

Read and write NFC tags, such as loyalty cards, access badges, stickers, and smart cards, from your Android app.
The Accept SDK opens a session on the tapped tag through the device's own contactless reader, and your app sends
commands to it one at a time.

- A [supported device](#supported-devices-and-tags).
- The Accept SDK [installed and initialized](../integration/sdk_integration#initialization).

Tag sessions don't need an authenticated merchant, the Tapaya Terminal plugin, or location permission. They ship in optional artifacts:
add them only if you need them; card payments work the same with or without them. The artifacts declare the
permissions they use: `android.permission.NFC` for phones, and `com.sunmi.perm.CONTACTLESS_CARD` for Sunmi
terminals. Android NFC is declared as optional, so Google Play still offers your app on devices without it. `accept-nfc-sunmi` also adds a `<queries>` entry for Sunmi's pay service and embeds Sunmi PayLib.

### Supported devices and tags [#supported-devices-and-tags]

| Device | Reader | Artifacts |
| :--- | :--- | :--- |
| Android phones and tablets with NFC | Android NFC | `com.tapaya:accept-nfc` |
| Sunmi P-series terminals | The payment module's contactless reader, through Sunmi's pay service | `com.tapaya:accept-nfc` and `com.tapaya:accept-nfc-sunmi` |

Sunmi P-series terminals have no Android NFC; their antenna sits behind the payment module, so they need the
Sunmi artifact as well. On a device with neither reader, `isSupported()` returns `false` and `openSession()` fails
with `NOT_SUPPORTED`.

| Tag type | Examples |
| :--- | :--- |
| [NFC Type 2](#nfc-type-2) | NTAG, MIFARE Ultralight, Ultralight EV1, Ultralight C |
| [MIFARE Classic](#mifare-classic) | MIFARE Classic Mini, 1K, 4K |
| [ISO-DEP smart cards](#iso-dep-smart-cards) | MIFARE DESFire |

Some phones' NFC controllers can't talk to MIFARE Classic. On those phones, Classic operations fail with
`NOT_SUPPORTED`.

<Callout title="Check support, not the device model" type="info">
Call [`isSupported()`](#check-support) to decide whether to show the tag feature, instead of matching device
models. It returns `true` on a phone whose NFC is switched off; `openSession()` then fails with
`NFC_DISABLED`, so you can ask the user to turn NFC on.
</Callout>

### How it works [#how-it-works]

1. Your app calls `Accept.nfc.openSession(activity)`.
2. The SDK turns on the reader and waits for a tap.
3. The customer taps a tag, and `openSession()` returns a `TagSession` carrying the tag's UID and family.
4. Your app reads and writes through the session, one command at a time.
5. Your app calls `close()`, which frees the reader for payments and other sessions.

<Callout title="Payments always take priority" type="warn">
The device has one contactless reader. Starting a payment with `Accept.payments.pay()` takes it back: an open
session ends with `PAYMENT`, and `openSession()` fails with `READER_BUSY` until the payment is over. Be ready
for a session to end at any point; see [End a session](#end-a-session).
</Callout>

## Integrate [#integrate]

<div className="fd-steps [&_h3]:fd-step">

### Install [#install]

Add `accept-nfc` next to the core SDK. Add `accept-nfc-sunmi` too if your app runs on Sunmi P-series terminals.
Keep all Accept artifacts on the same version. On React Native, set the config plugin's `nfc` option instead:
`true` for phones, or `{ "sunmi": true }` to add Sunmi P-series terminals. Then run `npx expo prebuild` again.

<CodeBlockTabs defaultValue="kotlin" groupId="accept-language" persist>
<CodeBlockTabsList>
<CodeBlockTabsTrigger value="kotlin">
Android (Kotlin)
</CodeBlockTabsTrigger>

<CodeBlockTabsTrigger value="typescript">
React Native (TypeScript)
</CodeBlockTabsTrigger>
</CodeBlockTabsList>

<CodeBlockTab value="kotlin">
```kotlin title="build.gradle.kts"
dependencies {
    implementation("com.tapaya:accept:$acceptVersion")
    implementation("com.tapaya:accept-nfc:$acceptVersion")
    // Sunmi P-series terminals only
    implementation("com.tapaya:accept-nfc-sunmi:$acceptVersion")
}
```
</CodeBlockTab>

<CodeBlockTab value="typescript">
```json title="app.json"
{
  "expo": {
    "plugins": [["@tapayadot/accept-react-native", { "nfc": { "sunmi": true } }]]
  }
}
```
</CodeBlockTab>
</CodeBlockTabs>

The artifacts register themselves at app startup, so there is nothing to set up in code. On Android, `Accept.nfc`
is an extension property; import it before use:

```kotlin
import com.tapaya.accept.nfc.nfc
```

### Check support [#check-support]

Call `isSupported()` to decide whether to show the tag feature at all:

<CodeBlockTabs defaultValue="kotlin" groupId="accept-language" persist>
<CodeBlockTabsList>
<CodeBlockTabsTrigger value="kotlin">
Android (Kotlin)
</CodeBlockTabsTrigger>

<CodeBlockTabsTrigger value="typescript">
React Native (TypeScript)
</CodeBlockTabsTrigger>
</CodeBlockTabsList>

<CodeBlockTab value="kotlin">
```kotlin
if (Accept.nfc.isSupported()) {
    showScanTagButton()
}
```
</CodeBlockTab>

<CodeBlockTab value="typescript">
```typescript
if (Accept.nfc.isSupported()) {
    showScanTagButton();
}
```
</CodeBlockTab>
</CodeBlockTabs>

`isSupported()` needs no tap and doesn't touch the reader, so it's safe to call while a payment is running. It
throws `NotInitialized` if `Accept.initialize` hasn't been called yet. On React Native without the `nfc` option, it
returns `false`, and `openSession()` fails with `ERR_NFC_NOT_CONFIGURED`.

### Open a session [#open-a-session]

On Android, pass the activity that is in the foreground. It must be resumed, or `openSession()` throws
`IllegalStateException`. React Native uses the foreground activity for you.

<CodeBlockTabs defaultValue="kotlin" groupId="accept-language" persist>
<CodeBlockTabsList>
<CodeBlockTabsTrigger value="kotlin">
Android (Kotlin)
</CodeBlockTabsTrigger>

<CodeBlockTabsTrigger value="typescript">
React Native (TypeScript)
</CodeBlockTabsTrigger>
</CodeBlockTabsList>

<CodeBlockTab value="kotlin">
```kotlin
val session = try {
    Accept.nfc.openSession(activity)
} catch (e: TagSessionException) {
    when (e.reason) {
        TagErrorReason.TIMEOUT -> showMessage("No tag detected. Try again.")
        TagErrorReason.READER_BUSY -> showMessage("The reader is busy. Try again soon.")
        TagErrorReason.NFC_DISABLED -> showMessage("Turn on NFC in your phone's settings.")
        else -> showMessage("Can't read tags on this device.")
    }
    return
}

try {
    showTag(session.info.uidHex, session.info.family)
    // read and write...
} finally {
    session.close()
}
```
</CodeBlockTab>

<CodeBlockTab value="typescript">
```typescript
import Accept, { TagSessionError } from '@tapayadot/accept-react-native';

let session;
try {
    session = await Accept.nfc.openSession();
} catch (error) {
    if (!TagSessionError.is(error)) throw error;
    switch (error.reason) {
        case 'TIMEOUT': showMessage('No tag detected. Try again.'); break;
        case 'READER_BUSY': showMessage('The reader is busy. Try again soon.'); break;
        case 'NFC_DISABLED': showMessage("Turn on NFC in your phone's settings."); break;
        default: showMessage("Can't read tags on this device.");
    }
    return;
}

try {
    showTag(session.info.uidHex, session.info.family);
    // read and write...
} finally {
    await session.close();
}
```
</CodeBlockTab>
</CodeBlockTabs>

`openSession()` suspends until a tag is tapped or `tapWait` runs out (30 seconds by default). Show a "Tap your
card" prompt while it waits. It throws `IllegalStateException` if `activity` isn't resumed.

On a phone, the activity matters: Android reads tags only for it, and leaving the foreground stops the wait or ends
the session with `ACTIVITY_PAUSED`. Sunmi terminals read tags whatever is in the foreground, but you still pass an
activity.

To stop waiting on Android, for example when the customer taps **Cancel**, cancel the coroutine that called
`openSession()`. On React Native, the wait ends when `tapWaitMs` runs out.

On phones, Android reads tags only for the app in the foreground. If the activity you passed leaves the
foreground, the session ends with `ACTIVITY_PAUSED`. On Sunmi terminals, the reader works whatever is in the
foreground.

<Accordions type="multiple">
<Accordion title="Session info fields" id="session-info">
`session.info` describes the tapped tag. Hex values are upper-case, with no separators.

| Field | Description |
| :--- | :--- |
| `uidHex` | The tag's UID, e.g. `04A1B2C3D4E5F6`. |
| `family` | The `TagFamily`, which tells you which operations apply. |
| `sak`, `atqaHex` | The SAK byte and ATQA the tag returned when it was selected. |
| `atsHex` | ISO-DEP tags only, otherwise `null`. The full ATS on Sunmi terminals; on phones, only its historical bytes, because Android doesn't expose the rest. |
| `memoryBytes` | Memory size, when the tag family determines it; otherwise `null`. |
| `versionHex` | `GET_VERSION` response, for tags that support it; otherwise `null`. |
</Accordion>
</Accordions>

### Read and write a tag [#read-and-write-a-tag]

Branch on `session.info.family`, then use the operations for that tag type:

<CodeBlockTabs defaultValue="kotlin" groupId="accept-language" persist>
<CodeBlockTabsList>
<CodeBlockTabsTrigger value="kotlin">
Android (Kotlin)
</CodeBlockTabsTrigger>

<CodeBlockTabsTrigger value="typescript">
React Native (TypeScript)
</CodeBlockTabsTrigger>
</CodeBlockTabsList>

<CodeBlockTab value="kotlin">
```kotlin
when (session.info.family) {
    TagFamily.NTAG, TagFamily.ULTRALIGHT, TagFamily.ULTRALIGHT_EV1,
    TagFamily.ULTRALIGHT_C, TagFamily.TYPE2_OTHER -> readType2Tag(session)
    TagFamily.MIFARE_CLASSIC_MINI, TagFamily.MIFARE_CLASSIC_1K,
    TagFamily.MIFARE_CLASSIC_4K -> readClassicCard(session)
    TagFamily.ISO_DEP -> readSmartCard(session)
    TagFamily.UNKNOWN -> showMessage("This tag isn't supported.")
}
```
</CodeBlockTab>

<CodeBlockTab value="typescript">
```typescript
switch (session.info.family) {
    case 'NTAG': case 'ULTRALIGHT': case 'ULTRALIGHT_EV1':
    case 'ULTRALIGHT_C': case 'TYPE2_OTHER': await readType2Tag(session); break;
    case 'MIFARE_CLASSIC_MINI': case 'MIFARE_CLASSIC_1K':
    case 'MIFARE_CLASSIC_4K': await readClassicCard(session); break;
    case 'ISO_DEP': await readSmartCard(session); break;
    case 'UNKNOWN': showMessage("This tag isn't supported."); break;
}
```
</CodeBlockTab>
</CodeBlockTabs>

A command that doesn't fit the tapped tag fails with `NOT_SUPPORTED`, and the session stays open. Bytes are
`ByteArray` on Android and `Uint8Array` on React Native.

<Accordions type="multiple">
<Accordion title="NFC Type 2" id="nfc-type-2">
NTAG, MIFARE Ultralight, Ultralight EV1, Ultralight C, and other Type 2 tags (`TYPE2_OTHER`).

| Operation | What it does |
| :--- | :--- |
| `readPages(startPage)` | Returns 16 bytes: four 4-byte pages starting at `startPage`. |
| `writePage(page, data)` | Writes one 4-byte page. |
| `passwordAuth(password)` | NTAG and Ultralight EV1 only. Unlocks protected pages with a 4-byte password and returns the tag's PACK, which you can use to check that the tag is genuine. |
| `ultralightCAuth(key)` | Ultralight C only. Authenticates with a 16-byte 3DES key. |
| `transceiveType2(frame)` | Sends a raw Type 2 frame, for commands without a dedicated method, and returns the tag's raw answer. |

<CodeBlockTabs defaultValue="kotlin" groupId="accept-language" persist>
<CodeBlockTabsList>
<CodeBlockTabsTrigger value="kotlin">
Android (Kotlin)
</CodeBlockTabsTrigger>

<CodeBlockTabsTrigger value="typescript">
React Native (TypeScript)
</CodeBlockTabsTrigger>
</CodeBlockTabsList>

<CodeBlockTab value="kotlin">
```kotlin
// Protected NTAG and Ultralight EV1 tags only
session.passwordAuth(password = byteArrayOf(0x12, 0x34, 0x56, 0x78))

val pages = session.readPages(startPage = 4)  // pages 4 to 7
session.writePage(page = 4, data = byteArrayOf(0x01, 0x02, 0x03, 0x04))

// Raw GET_VERSION command
val version = session.transceiveType2(byteArrayOf(0x60))
```
</CodeBlockTab>

<CodeBlockTab value="typescript">
```typescript
// Protected NTAG and Ultralight EV1 tags only
await session.passwordAuth(Uint8Array.of(0x12, 0x34, 0x56, 0x78));

const pages = await session.readPages(4); // pages 4 to 7
await session.writePage(4, Uint8Array.of(0x01, 0x02, 0x03, 0x04));

// Raw GET_VERSION command
const version = await session.transceiveType2(Uint8Array.of(0x60));
```
</CodeBlockTab>
</CodeBlockTabs>
</Accordion>

<Accordion title="MIFARE Classic" id="mifare-classic">
MIFARE Classic Mini, 1K, and 4K. Authenticate a sector before you read or write its blocks.

| Operation | What it does |
| :--- | :--- |
| `authenticateClassic(block, keyType, key)` | Authenticates the sector that holds `block` with a 6-byte key A or B. |
| `readBlock(block)` | Returns the block's 16 bytes. |
| `writeBlock(block, data)` | Writes 16 bytes to the block. |
| `increment(block, value)`, `decrement(block, value)` | Add or subtract a non-negative `value` in the card's operand register. Follow with `transfer`. |
| `restore(block)` | Loads a value block into the operand register. |
| `transfer(block)` | Writes the operand register to a block. |

<CodeBlockTabs defaultValue="kotlin" groupId="accept-language" persist>
<CodeBlockTabsList>
<CodeBlockTabsTrigger value="kotlin">
Android (Kotlin)
</CodeBlockTabsTrigger>

<CodeBlockTabsTrigger value="typescript">
React Native (TypeScript)
</CodeBlockTabsTrigger>
</CodeBlockTabsList>

<CodeBlockTab value="kotlin">
```kotlin
session.authenticateClassic(block = 4, keyType = MifareKeyType.A, key = sectorKey)
val block = session.readBlock(4)
session.writeBlock(4, newContent)

// Value blocks: change the value, then write it back
session.decrement(block = 5, value = 1)
session.transfer(block = 5)
```
</CodeBlockTab>

<CodeBlockTab value="typescript">
```typescript
await session.authenticateClassic(4, 'A', sectorKey);
const block = await session.readBlock(4);
await session.writeBlock(4, newContent);

// Value blocks: change the value, then write it back
await session.decrement(5, 1);
await session.transfer(5);
```
</CodeBlockTab>
</CodeBlockTabs>

A wrong key fails with `AUTH_FAILED`, and the SDK selects the tag again before your next command, so you can try
the next key straight away:

<CodeBlockTabs defaultValue="kotlin" groupId="accept-language" persist>
<CodeBlockTabsList>
<CodeBlockTabsTrigger value="kotlin">
Android (Kotlin)
</CodeBlockTabsTrigger>

<CodeBlockTabsTrigger value="typescript">
React Native (TypeScript)
</CodeBlockTabsTrigger>
</CodeBlockTabsList>

<CodeBlockTab value="kotlin">
```kotlin
val key = candidateKeys.firstOrNull { key ->
    try {
        session.authenticateClassic(block = 4, keyType = MifareKeyType.A, key = key)
        true
    } catch (e: TagSessionException) {
        if (e.reason != TagErrorReason.AUTH_FAILED) throw e
        false
    }
} ?: error("no key for sector 1")
```
</CodeBlockTab>

<CodeBlockTab value="typescript">
```typescript
let found: Uint8Array | undefined;
for (const key of candidateKeys) {
    try {
        await session.authenticateClassic(4, 'A', key);
        found = key;
        break;
    } catch (error) {
        if (!TagSessionError.is(error) || error.reason !== 'AUTH_FAILED') throw error;
    }
}
if (!found) throw new Error('no key for sector 1');
```
</CodeBlockTab>
</CodeBlockTabs>
</Accordion>

<Accordion title="ISO-DEP smart cards" id="iso-dep-smart-cards">
MIFARE DESFire and other ISO 14443-4 cards. Use `transmitApdu(apdu)` to send one command APDU; it returns the
response: the data followed by SW1 SW2. The SDK doesn't interpret the status words.

<CodeBlockTabs defaultValue="kotlin" groupId="accept-language" persist>
<CodeBlockTabsList>
<CodeBlockTabsTrigger value="kotlin">
Android (Kotlin)
</CodeBlockTabsTrigger>

<CodeBlockTabsTrigger value="typescript">
React Native (TypeScript)
</CodeBlockTabsTrigger>
</CodeBlockTabsList>

<CodeBlockTab value="kotlin">
```kotlin
val select = byteArrayOf(0x00, 0xA4.toByte(), 0x04, 0x00, 0x07,
    0xA0.toByte(), 0x00, 0x00, 0x00, 0x03, 0x10, 0x10, 0x00)
val response = session.transmitApdu(select)
val sw = response.takeLast(2)   // [0x90, 0x00] on success
```
</CodeBlockTab>

<CodeBlockTab value="typescript">
```typescript
const select = Uint8Array.of(0x00, 0xa4, 0x04, 0x00, 0x07,
    0xa0, 0x00, 0x00, 0x00, 0x03, 0x10, 0x10, 0x00);
const response = await session.transmitApdu(select);
const sw = response.slice(-2); // [0x90, 0x00] on success
```
</CodeBlockTab>
</CodeBlockTabs>
</Accordion>
</Accordions>

### End a session [#end-a-session]

Call `close()` as soon as you're done, ideally from a `finally` block. Until you do, no other session can use the
reader. Closing a session that has already ended does nothing.

A session can also end on its own. On Android, `session.ended` is a `StateFlow` that stays `null` while the
session is live, then emits the reason it ended. On React Native, it is a promise that resolves once with the
reason:

<CodeBlockTabs defaultValue="kotlin" groupId="accept-language" persist>
<CodeBlockTabsList>
<CodeBlockTabsTrigger value="kotlin">
Android (Kotlin)
</CodeBlockTabsTrigger>

<CodeBlockTabsTrigger value="typescript">
React Native (TypeScript)
</CodeBlockTabsTrigger>
</CodeBlockTabsList>

<CodeBlockTab value="kotlin">
```kotlin
session.ended.filterNotNull().first().let { reason ->
    when (reason) {
        TagSessionEndReason.CARD_REMOVED -> showMessage("Card removed")
        TagSessionEndReason.PAYMENT -> showMessage("A payment took over the reader")
        TagSessionEndReason.ACTIVITY_PAUSED -> showMessage("Keep the app in the foreground")
        else -> Unit
    }
}
```
</CodeBlockTab>

<CodeBlockTab value="typescript">
```typescript
session.ended.then((reason) => {
    switch (reason) {
        case 'CARD_REMOVED': showMessage('Card removed'); break;
        case 'PAYMENT': showMessage('A payment took over the reader'); break;
        case 'ACTIVITY_PAUSED': showMessage('Keep the app in the foreground'); break;
    }
});
```
</CodeBlockTab>
</CodeBlockTabs>

| `TagSessionEndReason` | When it happens |
| :--- | :--- |
| `CLOSED` | Your app called `close()`. |
| `CARD_REMOVED` | The tag left the field and wasn't selected again within the `reselect` timeout, or a different tag came back. |
| `IDLE_TIMEOUT` | No command arrived within the `idle` timeout (10 seconds by default). |
| `PAYMENT` | A payment started through `Accept.payments.pay()`. Payments always take priority. |
| `ACTIVITY_PAUSED` | Phones only: the activity the session was opened with left the foreground. |
| `READER_LOST` | The reader went away. On Sunmi terminals, the connection to the pay service dropped. |

Once a session has ended, every further command fails with `SESSION_ENDED`. Call `openSession()` again for a new
tap.

</div>

## Good to know [#good-to-know]

- **One session at a time.** The device has one reader. A second `openSession()` while a session is open or
  waiting fails with `READER_BUSY`.
- **Commands run in order.** Session methods can be called from any coroutine; they reach the tag one at a time,
  in the order you call them.
- **Permanent writes aren't guarded.** Lock bits, OTP pages, MIFARE Classic sector trailers, and passwords are
  written exactly as you send them. Double-check these writes; a mistake can lock the tag for good.

## Test the integration [#test-the-integration]

On each kind of device you ship to:

1. Check that `isSupported()` returns `true` on a phone with NFC and on a Sunmi terminal with `accept-nfc-sunmi`.
2. On a phone, switch NFC off and confirm `openSession()` fails with `NFC_DISABLED`.
3. Tap an NTAG or Ultralight tag and verify the session reports the right UID and `readPages(0)` returns 16
   bytes. Then `writePage` and read the page back.
4. On MIFARE Classic, authenticate with a wrong key and confirm `AUTH_FAILED`, then with the right one.
5. Cancel `openSession()` during the tap wait and open a new session straight away.
6. Start a payment during a session: the session should end as `PAYMENT` and the payment go through. Remove the
   tag during another session: it should end as `CARD_REMOVED`.
7. On a phone, send your app to the background during a session and confirm it ends as `ACTIVITY_PAUSED`.

## Handle errors [#handle-errors]

Tag failures throw `TagSessionException`, whose `reason` tells you what to do next. `TagSessionException` is
**not** an `AcceptException`. The only Accept SDK exception tag sessions throw is `NotInitialized`, when
`Accept.initialize` hasn't been called yet. On React Native, failures reject with `TagSessionError`, which carries
the same `reason`, `authLost`, and `vendorCode`; check for it with `TagSessionError.is()`.

<CodeBlockTabs defaultValue="kotlin" groupId="accept-language" persist>
<CodeBlockTabsList>
<CodeBlockTabsTrigger value="kotlin">
Android (Kotlin)
</CodeBlockTabsTrigger>

<CodeBlockTabsTrigger value="typescript">
React Native (TypeScript)
</CodeBlockTabsTrigger>
</CodeBlockTabsList>

<CodeBlockTab value="kotlin">
```kotlin
try {
    val session = Accept.nfc.openSession(activity)
    // ...
} catch (e: TagSessionException) {
    // reason-specific handling, see the tables below
}
```
</CodeBlockTab>

<CodeBlockTab value="typescript">
```typescript
try {
    const session = await Accept.nfc.openSession();
    // ...
} catch (error) {
    if (!TagSessionError.is(error)) throw error;
    // reason-specific handling, see the tables below
}
```
</CodeBlockTab>
</CodeBlockTabs>

<Callout title="Re-authenticate when authLost is set" type="warn">
After a failure from the tag or reader (`NAK`, `NO_RESPONSE`, `TIMEOUT`, `VENDOR_ERROR`, or `AUTH_FAILED`), the
SDK selects the tag again before the next command, which drops authentication. When that happens, the
exception's `authLost` flag is set: authenticate again before sending another command to protected memory. On
ISO-DEP cards such as DESFire, re-select the application as well. Until you authenticate again, MIFARE Classic
block commands fail with `AUTH_FAILED` without reaching the tag.
</Callout>

A key, block, or page argument of the wrong length or sign, or a value below zero, throws
`IllegalArgumentException` before anything reaches the tag.

<Accordions type="multiple">
<Accordion title="Opening a session" id="opening-a-session">
| `reason` | When it happens | What to do |
| :--- | :--- | :--- |
| `TIMEOUT` | No tap within `tapWait`. | Prompt again, or give up. |
| `READER_BUSY` | A payment or another session is using the reader. | Retry later; there is no queue. |
| `SESSION_ENDED` | A payment started, or the activity left the foreground, while `openSession()` was waiting. | Open a new session when the user is ready. |
| `NFC_DISABLED` | Phones only: NFC is switched off in the system settings. | Ask the user to turn NFC on. |
| `VENDOR_ERROR` | Sunmi terminals only: the pay service is unavailable. | Retry. If it keeps failing, report it with `vendorCode`. |
| `NOT_SUPPORTED` | The device has no reader the SDK can use. | Hide the feature when `isSupported()` returns `false`. |
</Accordion>

<Accordion title="Sending a command" id="sending-a-command">
| `reason` | When it happens | What to do |
| :--- | :--- | :--- |
| `TIMEOUT` | The command took longer than the `operation` timeout. | Retry. If `authLost` is set, authenticate first. |
| `NO_RESPONSE` | The tag didn't answer. | Retry if the tag is still in the field. |
| `AUTH_FAILED` | Wrong key or password. | Try the next key. |
| `NAK` | The tag refused the command: page out of range, protected memory, or an unsupported command. | Fix the command. The session continues. |
| `NOT_SUPPORTED` | The command doesn't fit this tag family, or the phone can't talk to MIFARE Classic. | Check `session.info.family`. The session continues. |
| `CARD_REMOVED` | The tag left the field during the command. | Open a new session. |
| `SESSION_ENDED` | A command was sent after the session ended. | Open a new session. |
| `VENDOR_ERROR` | The reader hardware reported a fault; `vendorCode` holds its code, when it gave one. | Report it to [developer support](/support/contacts#developer-support) with `vendorCode`. |
</Accordion>

<Accordion title="Change the timeouts" id="timeouts">
Pass `TagTimeouts` to `openSession()` to change the defaults. On React Native, the same timeouts are
milliseconds: `tapWaitMs`, `operationMs`, `reselectMs`, and `idleMs`.

<CodeBlockTabs defaultValue="kotlin" groupId="accept-language" persist>
<CodeBlockTabsList>
<CodeBlockTabsTrigger value="kotlin">
Android (Kotlin)
</CodeBlockTabsTrigger>

<CodeBlockTabsTrigger value="typescript">
React Native (TypeScript)
</CodeBlockTabsTrigger>
</CodeBlockTabsList>

<CodeBlockTab value="kotlin">
```kotlin
Accept.nfc.openSession(activity, TagTimeouts(tapWait = 15.seconds, idle = 30.seconds))
```
</CodeBlockTab>

<CodeBlockTab value="typescript">
```typescript
await Accept.nfc.openSession({ tapWaitMs: 15_000, idleMs: 30_000 });
```
</CodeBlockTab>
</CodeBlockTabs>

| Timeout | Default | Maximum | Applies to |
| :--- | :--- | :--- | :--- |
| `tapWait` | 30 s | 60 s | Waiting for the tap in `openSession()` |
| `operation` | 1 s | 5 s | Each command on the tag |
| `reselect` | 1 s | 5 s | Selecting the tag again after a failed command |
| `idle` | 10 s | 60 s | Time between commands before the session ends |

Every value must be greater than zero. Constructing `TagTimeouts` with a value outside these ranges throws
`IllegalArgumentException`.
</Accordion>
</Accordions>