The **nfctech** module provides methods for reading and writing tags that use different Near-Field Communication (NFC) technologies.
> **NOTE**
>
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## **Modules to Import**
```js
importtagfrom'@ohos.nfc.tag';
```
## NfcATag
Provides access to NFC-A (ISO 14443-3A) properties and I/O operations. **NfcATag** inherits from **TagSession**.
**TagSession** is the base class of all NFC tag technologies. It provides common interfaces for establishing connections and transferring data. For more details, see [TagSession](js-apis-tagSession.md).
The following describes the unique interfaces of **NfcATag**.
// tagInfo is an object given by the NFC service when a tag is dispatched.
letatqa=tag.getNfcATag(taginfo).getAtqa();
console.log("atqa:"+atqa);
```
## NfcBTag
Provides access to NFC-B (ISO 14443-3B) properties and I/O operations. **NfcBTag** inherits from **TagSession**.
**TagSession** is the base class of all NFC tag technologies. It provides common interfaces for establishing connections and transferring data. For more details, see [TagSession](js-apis-tagSession.md).
The following describes the unique interfaces of **NfcBTag**.
Provides access to NFC-F(JIS 6319-4) properties and I/O operations. **NfcFTag** inherits from **TagSession**.
**TagSession** is the base class of all NFC tag technologies. It provides common interfaces for establishing connections and transferring data. For more details, see [TagSession](js-apis-tagSession.md).
The following describes the unique interfaces of **NfcFTag**.
// tagInfo is an object given by the NFC service when a tag is dispatched.
letpmm=tag.getNfcFTag(taginfo).getPmm();
console.log("pmm:"+pmm);
```
## NfcVTag
Provides access to NFC-V (ISO 15693) properties and I/O operations. **NfcVTag** inherits from **TagSession**.
**TagSession** is the base class of all NFC tag technologies. It provides common interfaces for establishing connections and transferring data. For more details, see [TagSession](js-apis-tagSession.md).
The following describes the unique interfaces of **NfcVTag**.
// tagInfo is an object given by the NFC service when a tag is dispatched.
letdsfId=tag.getNfcVTag(taginfo).getDsfId();
console.log("dsfId:"+dsfId);
```
## IsoDepTag<sup>9+</sup>
Provides access to ISO-DEP (ISO 14443-4) properties and I/O operations. **IsoDepTag** inherits from **TagSession**.
**TagSession** is the base class of all NFC tag technologies. It provides common interfaces for establishing connections and transferring data. For more details, see [TagSession](js-apis-tagSession.md).
The following describes the unique interfaces of **IsoDepTag**.
| Promise<boolean> | Promise used to return the result. If the extended APDU is supported, **true** is returned; otherwise, **false** is returned.|
**Example**
```js
importtagfrom'@ohos.nfc.tag';
// tagInfo is an object given by the NFC service when a tag is dispatched.
| callback | AsyncCallback\<boolean> | Yes | Callback invoked to return the result. If the extended APDU is supported, **true** is returned; otherwise, **false** is returned.|
```js
importtagfrom'@ohos.nfc.tag';
// tagInfo is an object given by the NFC service when a tag is dispatched.
Provides access to the tags in the NFC Data Exchange Format (NDEF). **NdefTag** inherits from **TagSession**.
**TagSession** is the base class of all NFC tag technologies. It provides common interfaces for establishing connections and transferring data. For more details, see [TagSession](js-apis-tagSession.md).
The following describes the unique interfaces of **NdefTag**.
| callback | AsyncCallback\<boolean> | Yes | Callback invoked to return the result. If the tag is writable, **true** is returned; otherwise, **false** is returned.|
**Example**
```js
importtagfrom'@ohos.nfc.tag';
// tagInfo is an object given by the NFC service when a tag is dispatched.
| Promise\<number> | Promise used to return the result. If **0** is returned, the operation is successful. If the operation fails, an error code is returned.|
**Example**
```js
importtagfrom'@ohos.nfc.tag';
// tagInfo is an object given by the NFC service when a tag is dispatched.
| Promise<boolean> | Promise used to return the result. If the tag can be set to read-only, **true** is returned; otherwise, **false** is returned.|
**Example**
```js
importtagfrom'@ohos.nfc.tag';
// tagInfo is an object given by the NFC service when a tag is dispatched.
| callback | AsyncCallback\<boolean> | Yes | Callback invoked to return the result. If the tag can be set to read-only, **true** is returned; otherwise, **false** is returned.|
**Example**
```js
importtagfrom'@ohos.nfc.tag';
// tagInfo is an object given by the NFC service when a tag is dispatched.
Provides access to MIFARE Classic properties and I/O operations. **MifareClassicTag** inherits from **TagSession**.
**TagSession** is the base class of all NFC tag technologies. It provides common interfaces for establishing connections and transferring data. For more details, see [TagSession](js-apis-tagSession.md).
The following describes the unique interfaces of **MifareClassicTag**.
Authenticates a sector using the key. The sector can be accessed only after the authentication is successful. This API uses a promise to return the result.
Authenticates a sector using the key. The sector can be accessed only after the authentication is successful. This API uses an asynchronous callback to return the result.
| Promise\<number> | Promise used to return the result. If **0** is returned, the operation is successful. If the operation fails, an error code is returned.|
**Example**
```js
importtagfrom'@ohos.nfc.tag';
letdata="xxx";
// tagInfo is an object given by the NFC service when a tag is dispatched.
| Promise\<number> | Promise used to return the result. If **0** is returned, the operation is successful. If the operation fails, an error code is returned.|
**Example**
```js
importtagfrom'@ohos.nfc.tag';
// tagInfo is an object given by the NFC service when a tag is dispatched.
| Promise\<number> | Promise used to return the result. If **0** is returned, the operation is successful. If the operation fails, an error code is returned.|
**Example**
```js
importtagfrom'@ohos.nfc.tag';
// tagInfo is an object given by the NFC service when a tag is dispatched.
| Promise\<number> | Promise used to return the result. If **0** is returned, the operation is successful. If the operation fails, an error code is returned.|
**Example**
```js
importtagfrom'@ohos.nfc.tag';
// tagInfo is an object given by the NFC service when a tag is dispatched.
| Promise\<number> | Promise used to return the result. If **0** is returned, the operation is successful. If the operation fails, an error code is returned.|
**Example**
```js
importtagfrom'@ohos.nfc.tag';
// tagInfo is an object given by the NFC service when a tag is dispatched.
Provides access to MIFARE Ultralight properties and I/O operations. **MifareUltralightTag** inherits from **TagSession**.
**TagSession** is the base class of all NFC tag technologies. It provides common interfaces for establishing connections and transferring data. For more details, see [TagSession](js-apis-tagSession.md).
The following describes the unique interfaces of **MifareUltralightTag**.
| Promise\<number> | Promise used to return the result. If **0** is returned, the operation is successful. If the operation fails, an error code is returned.|
**Example**
```js
importtagfrom'@ohos.nfc.tag';
// tagInfo is an object given by the NFC service when a tag is dispatched.
Provides methods for operating NDEF formattable tags. **NdefFormatableTag** inherits from **TagSession**.
**TagSession** is the base class of all NFC tag technologies. It provides common interfaces for establishing connections and transferring data. For more details, see [TagSession](js-apis-tagSession.md).
The following describes the unique interfaces of **NdefFormatableTag**.
| message | [NdefMessage](#ndefmessage9) | Yes | NDEF message to write when the formatting is successful. If it is **null**, the tag is formatted only and no data will be written.|
| Promise\<number> | Promise used to return the result. If **0** is returned, the operation is successful. If the operation fails, an error code is returned.|
**Example**
```js
importtagfrom'@ohos.nfc.tag';
// tagInfo is an object given by the NFC service when a tag is dispatched.
| message | [NdefMessage](#ndefmessage9) | Yes | NDEF message to write when the formatting is successful. If it is **null**, the tag is formatted only and no data will be written.|
| callback: AsyncCallback\<number> | Callback invoked to return the result.|
**Example**
```js
importtagfrom'@ohos.nfc.tag';
// tagInfo is an object given by the NFC service when a tag is dispatched.
Formats this tag as an NDEF tag, writes an NDEF message to the NDEF tag, and then sets the tag to read-only. This API uses a promise to return the result.
| message | [NdefMessage](#ndefmessage9) | Yes | NDEF message to write when the formatting is successful. If it is **null**, the tag is formatted only and no data will be written.|
| Promise\<number> | Promise used to return the result. If **0** is returned, the operation is successful. If the operation fails, an error code is returned.|
**Example**
```js
importtagfrom'@ohos.nfc.tag';
// tagInfo is an object given by the NFC service when a tag is dispatched.
Formats this tag as an NDEF tag, writes an NDEF message to the NDEF tag, and then sets the tag to read-only. This API uses an asynchronous callback to return the result.
| message | [NdefMessage](#ndefmessage9) | Yes | NDEF message to write when the formatting is successful. If it is **null**, the tag is formatted only and no data will be written.|
| callback: AsyncCallback\<number> | Callback invoked to return the result.|
**Example**
```js
importtagfrom'@ohos.nfc.tag';
// tagInfo is an object given by the NFC service when a tag is dispatched.
The **tagSession** module provides common APIs for establishing connections and transferring data.
> **NOTE**
>
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## **Modules to Import**
```js
importtagfrom'@ohos.nfc.tag';
```
## tagSession
Provides common APIs for establishing connections and transferring data. **tagSession** is the base class of all [NFC tag technologies](js-apis-nfctech.md).
A child class instance is required to access the following interfaces. You can use **get**XX**Tag()** to obtain a child class instance.
The specific method varies with the NFC tag technology in use. For details, see [nfcTag](js-apis-nfcTag.md).
### tagSession.connectTag
connectTag(): boolean;
Connects to this tag.
Call this method to set up a connection before reading data from or writing data to a tag.