# NFC Tag Technologies
The **nfctech** module provides APIs 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
import tag from '@ohos.nfc.tag';
```
## NfcATag
Provides access to NFC-A (ISO 14443-3A) properties and I/O operations. This class 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**.
### NfcATag.getSak
getSak(): number
Obtains the SAK value of this NFC-A tag.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Core
**Return value**
| **Type**| **Description** |
| ------------------ | --------------------------|
| number | SAK value obtained.|
**Example**
```js
import tag from '@ohos.nfc.tag';
// tagInfo is an object given by the NFC service when a tag is dispatched.
let sak = tag.getNfcATag(taginfo).getSak();
console.log("sak:" +sak);
```
### NfcATag.getAtqa
getAtqa(): number[]
Obtains the ATQA value of this NFC-A tag.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Core
**Return value**
| **Type**| **Description** |
| ------------------ | --------------------------|
| number[] | ATQA value obtained.|
**Example**
```js
import tag from '@ohos.nfc.tag';
// tagInfo is an object given by the NFC service when a tag is dispatched.
let atqa = tag.getNfcATag(taginfo).getAtqa();
console.log("atqa:" +atqa);
```
## NfcBTag
Provides access to NFC-B (ISO 14443-3B) properties and I/O operations. This class 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**.
### NfcBTag.getRespAppData
getRespAppData(): number[]
Obtains the application data of this NFC-B tag.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Core
**Return value**
| **Type**| **Description** |
| ------------------ | --------------------------|
| number[] | Application data obtained.|
**Example**
```js
import tag from '@ohos.nfc.tag';
// tagInfo is an object given by the NFC service when a tag is dispatched.
let appData = tag.getNfcBTag(taginfo).getRespAppData();
console.log("appData:" +appData);
```
### NfcBTag.getRespProtocol
getRespProtocol(): number[]
Obtains the protocol information of this NFC-B tag.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Core
**Return value**
| **Type**| **Description** |
| ------------------ | --------------------------|
| number[] | Protocol information obtained.|
**Example**
```js
import tag from '@ohos.nfc.tag';
// tagInfo is an object given by the NFC service when a tag is dispatched.
let protocol = tag.getNfcBTag(taginfo).getRespProtocol();
console.log("appData:" +protocol);
```
## NfcFTag
Provides access to NFC-F (JIS 6319-4) properties and I/O operations. This class 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**.
### NfcFTag.getSystemCode
getSystemCode(): number[]
Obtains the system code from this NFC-F tag.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Core
**Return value**
| **Type**| **Description** |
| ------------------ | --------------------------|
| number[] | System code obtained.|
**Example**
```js
import tag from '@ohos.nfc.tag';
// tagInfo is an object given by the NFC service when a tag is dispatched.
let systemCode = tag.getNfcFTag(taginfo).getSystemCode();
console.log("systemCode:" +systemCode);
```
### NfcFTag.getPmm
getPmm(): number[]
Obtains the PMm (consisting of the IC code and manufacturer parameters) information from this NFC-F tag.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC
**Return value**
| **Type**| **Description** |
| ------------------ | --------------------------|
| number[] | PMm information obtained.|
**Example**
```js
import tag from '@ohos.nfc.tag';
// tagInfo is an object given by the NFC service when a tag is dispatched.
let pmm = tag.getNfcFTag(taginfo).getPmm();
console.log("pmm:" +pmm);
```
## NfcVTag
Provides access to NFC-V (ISO 15693) properties and I/O operations. This class 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**.
### NfcvTag.getResponseFlags
getResponseFlags(): number
Obtains the response flags from this NFC-V tag.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC
**Return value**
| **Type**| **Description** |
| ------------------ | --------------------------|
| number | Response flags obtained.|
**Example**
```js
import tag from '@ohos.nfc.tag';
// tagInfo is an object given by the NFC service when a tag is dispatched.
let flags = tag.getNfcVTag(taginfo).getResponseFlags();
console.log("flags:" +flags);
```
### NfcvTag.getDsfId
getDsfId(): number
Obtains the data storage format identifier (DSFID) from this NFC-V tag.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC
**Return value**
| **Type**| **Description** |
| ------------------ | --------------------------|
| number | DSFID obtained.|
**Example**
```js
import tag from '@ohos.nfc.tag';
// tagInfo is an object given by the NFC service when a tag is dispatched.
let dsfId = tag.getNfcVTag(taginfo).getDsfId();
console.log("dsfId:" +dsfId);
```
## IsoDepTag9+
Provides access to ISO-DEP (ISO 14443-4) properties and I/O operations. This class 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**.
### IsoDepTag.getHistoricalBytes9+
getHistoricalBytes(): string
Obtains the historical bytes of this tag.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC
**Return value**
| **Type**| **Description** |
| ------------------ | --------------------------|
| string | Historical bytes obtained.|
**Example**
```js
import tag from '@ohos.nfc.tag';
// tagInfo is an object given by the NFC service when a tag is dispatched.
let historicalBytes = tag.getIsoDepTag(taginfo).getHistoricalBytes();
console.log("historicalBytes:" +historicalBytes);
```
### IsoDepTag.getHiLayerResponse9+
getHiLayerResponse(): string
Obtains the HiLayer response of this tag.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC
**Return value**
| **Type**| **Description** |
| ------------------ | --------------------------|
| string | HiLayer response obtained.|
**Example**
```js
import tag from '@ohos.nfc.tag';
// tagInfo is an object given by the NFC service when a tag is dispatched.
let hiLayerResponse = tag.getIsoDepTag(taginfo).getHiLayerResponse();
console.log("hiLayerResponse:" +hiLayerResponse);
```
### IsoDepTag.isExtendedApduSupported9+
isExtendedApduSupported(): Promise<boolean>
Checks whether an extended application protocol data unit (APDU) is supported. This API uses a promise to return the result.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC
**Return value**
| **Type**| **Description** |
| ------------------ | --------------------------|
| Promise<boolean> | Promise used to return the result. If the extended APDU is supported, **true** is returned; otherwise, **false** is returned.|
**Example**
```js
import tag from '@ohos.nfc.tag';
// tagInfo is an object given by the NFC service when a tag is dispatched.
tag.getIsoDepTag(taginfo).isExtendedApduSupported().then(function (has) {
console.log('has: ' + has)
})
```
### IsoDepTag.isExtendedApduSupported9+
isExtendedApduSupported(callback: AsyncCallback\): void
Checks whether an extended APDU is supported. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | -------------------------------------- |
| callback | AsyncCallback\ | Yes | Callback invoked to return the result. If the extended APDU is supported, **true** is returned; otherwise, **false** is returned.|
```js
import tag from '@ohos.nfc.tag';
// tagInfo is an object given by the NFC service when a tag is dispatched.
tag.getIsoDepTag(taginfo).isExtendedApduSupported(function (error, has) {
console.log(JSON.stringify(error))
console.log('has: ' + has)
})
```
## NdefTag9+
Provides access to the tags in the NFC Data Exchange Format (NDEF). This class 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**.
### NdefTag.createNdefMessage9+
createNdefMessage(data: string): [NdefMessage](#ndefmessage9)
Creates an NDEF message using raw bytes.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC
**Parameters**
| **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- |
| data | string | Yes| Raw bytes of the string type.|
**Return value**
| **Type**| **Description** |
| ------------------ | --------------------------|
| [NdefMessage](#ndefmessage9) | NDEF message created.|
**Example**
```js
import tag from '@ohos.nfc.tag';
// tagInfo is an object given by the NFC service when a tag is dispatched.
let NdefMessage = tag.NdefTag(taginfo).createNdefMessage(data);
```
## NdefMessage9+
### NdefMessage.getNdefRecords9+
getNdefRecords(): [NdefRecord](#ndefrecord9)[ ]
Obtains all NDEF records.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC
**Return value**
| **Type**| **Description** |
| ------------------ | --------------------------|
| [NdefRecord](#ndefrecord9)[ ] | All records obtained.|
**Example**
```js
import tag from '@ohos.nfc.tag';
// tagInfo is an object given by the NFC service when a tag is dispatched.
let NdefRecord = tag.NdefTag(taginfo).getNdefRecords();
```
## NdefRecord9+
| **Name**| **Type**| **Description**|
| -------- | -------- | -------- |
| tnf | number | UID of the tag.|
| [rtdType](#rtdtype9) | string | NFC Record Type Definition (RTD) supported by the tag.|
| id | string | Additional information about the tag.|
| payload | string | RF discovery ID of the tag.|
## RtdType9+
| **Name**| **Type**| **Description**|
| -------- | -------- | -------- |
| RTD_TEXT | 'T' | Text information.|
| RTD_URI | 'U' | Network address, email, or phone number.|
### NdefTag.createNdefMessage9+
createNdefMessage(ndefRecords: NdefRecord[]): [NdefMessage](#ndefmessage9)
Creates an NDEF message using the NDEF records.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC
**Parameters**
| **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- |
| ndefRecords | [NdefRecord](#ndefrecord9)[] | Yes| A list of NDEF records.|
**Return value**
| **Type**| **Description** |
| ------------------ | --------------------------|
| [NdefMessage](#ndefmessage9) | NDEF message created.|
**Example**
```js
import tag from '@ohos.nfc.tag';
// tagInfo is an object given by the NFC service when a tag is dispatched.
let NdefMessage = tag.NdefTag(taginfo).createNdefMessage(ndefRecords);
```
### NdefTag.getNdefTagType9+
getNdefTagType(): NfcForumType
Obtains the type of this NDEF tag.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC
**Return value**
| **Type**| **Description** |
| ------------------ | --------------------------|
| [NfcForumType](#nfcforumtype9) | NDEF tag type obtained.|
**Example**
```js
import tag from '@ohos.nfc.tag';
// tagInfo is an object given by the NFC service when a tag is dispatched.
let NfcForumType = tag.NdefTag(taginfo).getNdefTagType();
```
### NdefTag.getNdefMessage9+
getNdefMessage(): NdefMessage
Obtains the NDEF message from the tag discovered.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC
**Return value**
| **Type**| **Description** |
| ------------------ | --------------------------|
| [NdefMessage](#ndefmessage9) | NDEF message created.|
**Example**
```js
import tag from '@ohos.nfc.tag';
// tagInfo is an object given by the NFC service when a tag is dispatched.
let NdefMessage = tag.NdefTag(taginfo).getNdefMessage();
```
### NdefTag.isNdefWritable9+
isNdefWritable(): Promise<boolean>
Checks whether the NDEF tag is writable. This API uses a promise to return the result.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC
**Return value**
| **Type**| **Description** |
| ------------------ | --------------------------|
| Promise<boolean> | Promise used to return the result. If the tag is writable, **true** is returned; otherwise, **false** is returned.|
**Example**
```js
import tag from '@ohos.nfc.tag';
// tagInfo is an object given by the NFC service when a tag is dispatched.
tag.NdefTag(taginfo).isNdefWritable().then(function (has) {
console.log(JSON.stringify(has))
})
```
### NdefTag.isNdefWritable9+
isNdefWritable(callback: AsyncCallback<boolean>): void;
Checks whether the NDEF tag is writable. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | -------------------------------------- |
| callback | AsyncCallback\ | Yes | Callback invoked to return the result. If the tag is writable, **true** is returned; otherwise, **false** is returned.|
**Example**
```js
import tag from '@ohos.nfc.tag';
// tagInfo is an object given by the NFC service when a tag is dispatched.
tag.NdefTag(taginfo).isNdefWritable(function (error, has) {
console.log(JSON.stringify(error))
console.log('has: ' + has)
})
```
### NdefTag.readNdef9+
readNdef(): Promise\
Reads the NDEF message from this tag. This API uses a promise to return the result.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC
**Return value**
| **Type**| **Description** |
| ------------------ | --------------------------|
| Promise\<[NdefMessage](#ndefmessage9)> | Promise used to return the NDEF message read.|
**Example**
```js
import tag from '@ohos.nfc.tag';
// tagInfo is an object given by the NFC service when a tag is dispatched.
tag.NdefTag(taginfo).readNdef().then(function (ndefMessage) {
console.log(JSON.stringify(ndefMessage))
})
```
### NdefTag.readNdef9+
readNdef(callback: AsyncCallback\<[NdefMessage](#ndefmessage9)>): void
Reads the NDEF message from this tag. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | -------------------------------------- |
| callback | AsyncCallback\<[NdefMessage](#ndefmessage9)> | Yes | Callback invoked to return the result.|
**Example**
```js
import tag from '@ohos.nfc.tag';
// tagInfo is an object given by the NFC service when a tag is dispatched.
tag.NdefTag(taginfo).readNdef(function (error, ndefMessage) {
console.log(JSON.stringify(error))
console.log('ndefMessage: ' + ndefMessage)
})
```
### NdefTag.writeNdef9+
writeNdef(msg: NdefMessage): Promise\;
Writes an NDEF message to this tag. This API uses a promise to return the result.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | -------------------------------------- |
| msg | NdefMessage | Yes | NDEF message to write.|
**Return value**
| **Type**| **Description** |
| ------------------ | --------------------------|
| Promise\ | 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
import tag from '@ohos.nfc.tag';
// tagInfo is an object given by the NFC service when a tag is dispatched.
NdefTag.writeNdef(msg).then(function (netHandle) {
console.log(JSON.stringify(netHandle))
})
```
### NdefTag.writeNdef9+
writeNdef(msg: NdefMessage, callback: AsyncCallback\): void
Writes an NDEF message to this tag. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | -------------------------------------- |
| msg | NdefMessage | Yes | NDEF message to write.|
| callback | AsyncCallback\ | Yes | Callback invoked to return the result.|
**Example**
```js
import tag from '@ohos.nfc.tag';
// tagInfo is an object given by the NFC service when a tag is dispatched.
tag.NdefTag(taginfo).write(msg, function (error, has) {
console.log(JSON.stringify(error))
console.log('has: ' + has)
})
```
### NdefTag.canSetReadOnly9+
canSetReadOnly(): Promise\
Checks whether this NDEF tag can be set to read-only. This API uses a promise to return the result.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC
**Return value**
| **Type**| **Description** |
| ------------------ | --------------------------|
| 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
import tag from '@ohos.nfc.tag';
// tagInfo is an object given by the NFC service when a tag is dispatched.
tag.NdefTag(taginfo).canSetReadOnly().then(function (has) {
console.log(JSON.stringify(has))
})
```
### NdefTag.canSetReadOnly9+
canSetReadOnly(callback: AsyncCallback<boolean>): void;
Checks whether this NDEF tag can be set to read-only. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | -------------------------------------- |
| callback | AsyncCallback\ | 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
import tag from '@ohos.nfc.tag';
// tagInfo is an object given by the NFC service when a tag is dispatched.
tag.NdefTag(taginfo).canSetReadOnly(function (error, has) {
console.log(JSON.stringify(error))
console.log('has: ' + has)
})
```
### NdefTag.setReadOnly9+
setReadOnly(): Promise\
Sets this NDEF tag to read-only. This API uses a promise to return the result.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC
**Return value**
| **Type**| **Description** |
| ------------------ | --------------------------|
| Promise<number> | Promise used to return the result. If the operation is successful, **0** is returned; otherwise, an error code is returned.|
**Example**
```js
import tag from '@ohos.nfc.tag';
// tagInfo is an object given by the NFC service when a tag is dispatched.
tag.NdefTag(taginfo).setReadOnly().then(function (errcode) {
console.log(JSON.stringify(errcode))
})
```
### NdefTag.setReadOnly9+
setReadOnly(callback: AsyncCallback): void
Sets this NDEF tag to read-only. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | -------------------------------------- |
| callback | AsyncCallback\ | Yes | Callback invoked to return the result.|
**Example**
```js
import tag from '@ohos.nfc.tag';
// tagInfo is an object given by the NFC service when a tag is dispatched.
tag.NdefTag(taginfo).setReadOnly(function (error, errcode) {
console.log(JSON.stringify(error))
console.log('has: ' + errcode)
})
```
### NdefTag.getNdefTagTypeString9+
getNdefTagTypeString(type: [NfcForumType](#nfcforumtype9)): string
Converts an NFC Forum Type to a byte array defined in the NFC Forum.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | -------------------------------------- |
| type | [NfcForumType](#nfcforumtype9) | Yes | NFC Forum Type.|
**Return value**
| **Type**| **Description** |
| ------------------ | --------------------------|
| string | Byte array obtained.|
**Example**
```js
import tag from '@ohos.nfc.tag';
// tagInfo is an object given by the NFC service when a tag is dispatched.
let ndefTypeString= tag.NdefTag(taginfo).getNdefTagTypeString(type);
```
## NfcForumType9+
| **Name**| **Type**| **Description**|
| -------- | -------- | -------- |
| NFC_FORUM_TYPE_1 | 1 | NFC Forum Type 1.|
| NFC_FORUM_TYPE_2 | 2 | NFC Forum Type 2.|
| NFC_FORUM_TYPE_3 | 3 | NFC Forum Type 3.|
| NFC_FORUM_TYPE_4 | 4 | NFC Forum Type 4.|
| MIFARE_CLASSIC | 101 | MIFARE Classic.|
## MifareClassicTag 9+
Provides access to MIFARE Classic properties and I/O operations. This class 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**.
### MifareClassicTag.authenticateSector9+
authenticateSector(sectorIndex: number, key: number[], isKeyA: boolean): Promise\
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.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | -------------------------------------- |
| sectorIndex | number | Yes | Index of the sector to authenticate.|
| key | number[]| Yes | Key (6 bytes) used for authentication.|
| isKeyA | boolean | Yes | Whether the key is key A. The value **true** indicates key A, and **false** indicates key B.|
**Return value**
| **Type**| **Description** |
| ------------------ | --------------------------|
| Promise\ | Promise used to return the result. If the authentication is successful, **true** is returned. Otherwise, **false** is returned.|
**Example**
```js
import tag from '@ohos.nfc.tag';
// tagInfo is an object given by the NFC service when a tag is dispatched.
tag.MifareClassicTag(taginfo).authenticateSector(sectorIndex, key).then(function (isKeyA) {
console.log(JSON.stringify(isKeyA))
})
```
### MifareClassicTag.authenticateSector9+
authenticateSector(sectorIndex: number, key: number[], isKeyA: boolean, callback: AsyncCallback): void
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.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | -------------------------------------- |
| sectorIndex | number | Yes | Index of the sector to authenticate.|
| key | number[]| Yes | Key (6 bytes) used for authentication.|
| isKeyA | boolean | Yes | Whether the key is key A. The value **true** indicates key A, and **false** indicates key B.|
| callback | AsyncCallback\ | Yes | Callback invoked to return the result.|
**Example**
```js
import tag from '@ohos.nfc.tag';
// tagInfo is an object given by the NFC service when a tag is dispatched.
tag.MifareClassicTag(taginfo).authenticateSector(sectorIndex, key, function (error, has) {
console.log(JSON.stringify(error))
console.log('has: ' + has)
})
```
### MifareClassicTag.readSingleBlock9+
readSingleBlock(blockIndex: number): Promise\
Reads a block (16 bytes) on the tag. This API uses a promise to return the result.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | -------------------------------------- |
| blockIndex | number | Yes | Index of the block to read.|
**Return value**
| **Type**| **Description** |
| ------------------ | --------------------------|
| Promise\ | Promise used to return the block data read.|
**Example**
```js
import tag from '@ohos.nfc.tag';
let data = "xxx";
// tagInfo is an object given by the NFC service when a tag is dispatched.
tag.MifareClassicTag(taginfo).readSingleBlock(blockIndex).then(function (data){
console.log('data: ' + data)
})
```
### MifareClassicTag.readSingleBlock9+
readSingleBlock(blockIndex: number, callback: AsyncCallback\): void
Reads a block (16 bytes) on the tag. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | -------------------------------------- |
| blockIndex | number | Yes | Index of the block to read.|
| callback | AsyncCallback\ | Yes | Callback invoked to return the block read.|
**Example**
```js
import tag from '@ohos.nfc.tag';
let data = "xxx";
// tagInfo is an object given by the NFC service when a tag is dispatched.
tag.MifareClassicTag(taginfo).readSingleBlock(blockIndex, function (error, data) {
console.log(JSON.stringify(error))
console.log('data: ' + data)
})
```
### MifareClassicTag.writeSingleBlock9+
writeSingleBlock(blockIndex: number, data: string): Promise\
Writes data to a block on the tag. This API uses a promise to return the result.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | -------------------------------------- |
| blockIndex | number | Yes | Index of the target block.|
| data | string | Yes | Data to write.|
**Return value**
| **Type**| **Description** |
| ------------------ | --------------------------|
| Promise\ | 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
import tag from '@ohos.nfc.tag';
let data = "xxx";
// tagInfo is an object given by the NFC service when a tag is dispatched.
tag.MifareClassicTag(taginfo).writeSingleBlock(blockIndex, data).then(function (errcode){
console.log(JSON.stringify(errcode))
})
```
### MifareClassicTag.writeSingleBlock9+
writeSingleBlock(blockIndex: number, data: string, callback: AsyncCallback\): void
Writes data to a block on the tag. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | -------------------------------------- |
| blockIndex | number | Yes | Index of the target block.|
| data | string | Yes | Data to write.|
| callback | AsyncCallback\ | Yes | Callback invoked to return the result.|
**Example**
```js
import tag from '@ohos.nfc.tag';
let data = "xxx";
// tagInfo is an object given by the NFC service when a tag is dispatched.
tag.MifareClassicTag(taginfo).writeSingleBlock(blockIndex, data, function (error, errcode) {
console.log(JSON.stringify(error))
console.log(JSON.stringify(errcode))
})
```
### MifareClassicTag.incrementBlock9+
incrementBlock(blockIndex: number, value: number): Promise\
Increments a block with data. This API uses a promise to return the result.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | -------------------------------------- |
| blockIndex | number | Yes | Index of the block to increment.|
| value | number | Yes | Block data to increment. The value is a non-negative number.|
**Return value**
| **Type**| **Description** |
| ------------------ | --------------------------|
| Promise\ | 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
import tag from '@ohos.nfc.tag';
// tagInfo is an object given by the NFC service when a tag is dispatched.
tag.MifareClassicTag(taginfo).incrementBlock(blockIndex, value).then(function (errcode){
console.log(JSON.stringify(errcode))
})
```
### MifareClassicTag.incrementBlock9+
incrementBlock(blockIndex: number, value: number, callback: AsyncCallback\): void
Increments a block with data. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | -------------------------------------- |
| blockIndex | number | Yes | Index of the block to increment.|
| value | number | Yes | Block data to increment. The value is a non-negative number.|
| callback | AsyncCallback\ | Yes | Callback invoked to return the result.|
**Example**
```js
import tag from '@ohos.nfc.tag';
// tagInfo is an object given by the NFC service when a tag is dispatched.
tag.MifareClassicTag(taginfo).incrementBlock(blockIndex, value, function (error, errcode) {
console.log(JSON.stringify(error))
console.log(JSON.stringify(errcode))
})
```
### MifareClassicTag.decrementBlock9+
decrementBlock(blockIndex: number, value: number): Promise\
Decrements a block with data. This API uses a promise to return the result.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | -------------------------------------- |
| blockIndex | number | Yes | Index of the block to decrement.|
| value | number | Yes | Block data to decrement. The value is a non-negative number.|
**Return value**
| **Type**| **Description** |
| ------------------ | --------------------------|
| Promise\ | 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
import tag from '@ohos.nfc.tag';
// tagInfo is an object given by the NFC service when a tag is dispatched.
tag.MifareClassicTag(taginfo).decrementBlock(blockIndex, value).then(function (errcode){
console.log(JSON.stringify(errcode))
})
```
### MifareClassicTag.decrementBlock9+
decrementBlock(blockIndex: number, value: number, callback: AsyncCallback\): void
Decrements a block with data. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | -------------------------------------- |
| blockIndex | number | Yes | Index of the block to decrement.|
| value | number | Yes | Block data to decrement. The value is a non-negative number.|
| callback | AsyncCallback\ | Yes | Callback invoked to return the result.|
**Example**
```js
import tag from '@ohos.nfc.tag';
// tagInfo is an object given by the NFC service when a tag is dispatched.
tag.MifareClassicTag(taginfo).decrementBlock(blockIndex, value, function (error, errcode) {
console.log(JSON.stringify(error))
console.log(JSON.stringify(errcode))
})
```
### MifareClassicTag.transferToBlock9+
transferToBlock(blockIndex: number): Promise\
Copies data from the register to a block. This API uses a promise to return the result.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | -------------------------------------- |
| blockIndex | number | Yes | Index of the destination block.|
**Return value**
| **Type**| **Description** |
| ------------------ | --------------------------|
| Promise\ | 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
import tag from '@ohos.nfc.tag';
// tagInfo is an object given by the NFC service when a tag is dispatched.
tag.MifareClassicTag(taginfo).transferToBlock(blockIndex).then(function (errcode){
console.log(JSON.stringify(errcode))
})
```
### MifareClassicTag.transferToBlock
transferToBlock(blockIndex: number, callback: AsyncCallback\): void
Copies data from the register to a block. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | -------------------------------------- |
| blockIndex | number | Yes | Index of the destination block.|
| callback | AsyncCallback\ | Yes | Callback invoked to return the result.|
**Example**
```js
import tag from '@ohos.nfc.tag';
// tagInfo is an object given by the NFC service when a tag is dispatched.
tag.MifareClassicTag(taginfo).transferToBlock(blockIndex, function (error, errcode) {
console.log(JSON.stringify(error))
console.log(JSON.stringify(errcode))
})
```
### MifareClassicTag.restoreFromBlock9+
restoreFromBlock(blockIndex: number): Promise\
Copies data from a block to the register. This API uses a promise to return the result.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | -------------------------------------- |
| blockIndex | number | Yes | Index of the source block.|
**Return value**
| **Type**| **Description** |
| ------------------ | --------------------------|
| Promise\ | 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
import tag from '@ohos.nfc.tag';
// tagInfo is an object given by the NFC service when a tag is dispatched.
tag.MifareClassicTag(taginfo).restoreFromBlock(blockIndex).then(function (errcode){
console.log(JSON.stringify(errcode))
})
```
### MifareClassicTag.restoreFromBlock9+
restoreFromBlock(blockIndex: number, callback: AsyncCallback\): void
Copies data from a block to the register. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | -------------------------------------- |
| blockIndex | number | Yes | Index of the source block.|
| callback | AsyncCallback\ | Yes | Callback invoked to return the result.|
**Example**
```js
import tag from '@ohos.nfc.tag';
// tagInfo is an object given by the NFC service when a tag is dispatched.
tag.MifareClassicTag(taginfo).restoreFromBlock(blockIndex, function (error, errcode) {
console.log(JSON.stringify(error))
console.log(JSON.stringify(errcode))
})
```
### MifareClassicTag.getSectorCount9+
getSectorCount(): number
Obtains the number of sectors in this MIFARE Classic tag.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC
**Return value**
| **Type**| **Description** |
| ------------------ | --------------------------|
| number | Number of sectors obtained.|
**Example**
```js
import tag from '@ohos.nfc.tag';
// tagInfo is an object given by the NFC service when a tag is dispatched.
let setorCount = tag.MifareClassicTag(taginfo).getSectorCount();
```
### MifareClassicTag.getBlockCountInSector9+
getBlockCountInSector(sectorIndex: number): number
Obtains the number of blocks in a sector.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | -------------------------------------- |
| sectorIndex | number | Yes | Index of the sector.|
**Return value**
| **Type**| **Description** |
| ------------------ | --------------------------|
| number | Number of blocks obtained.|
**Example**
```js
import tag from '@ohos.nfc.tag';
// tagInfo is an object given by the NFC service when a tag is dispatched.
let blockNumber = tag.MifareClassicTag(taginfo).getBlockCountInSector(sectorIndex);
```
### MifareClassicTag.getType9+
getType(): [MifareClassicType](#mifareclassictype9)
Obtains the type of this MIFARE Classic tag.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC
**Return value**
| **Type**| **Description** |
| ------------------ | --------------------------|
| [MifareClassicType](#mifareclassictype9) | Type of the MIFARE Classic tag obtained.|
**Example**
```js
import tag from '@ohos.nfc.tag';
// tagInfo is an object given by the NFC service when a tag is dispatched.
let type = tag.MifareClassicTag(taginfo).getType();
```
### MifareClassicTag.getTagSize9+
getTagSize(): number
Obtains the tag size (in bytes). For details, see [MifareTagSize](#mifaretagsize9).
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC
**Return value**
| **Type**| **Description** |
| ------------------ | --------------------------|
| number | Tag size obtained, in bytes. For details, see [MifareTagSize](#mifaretagsize9).|
**Example**
```js
import tag from '@ohos.nfc.tag';
// tagInfo is an object given by the NFC service when a tag is dispatched.
let size = tag.MifareClassicTag(taginfo).getTagSize();
```
## MifareClassicType9+
| **Name**| **Value**| **Description**|
| -------- | -------- | -------- |
| TYPE_UNKNOWN | -1 | Unknown type.|
| TYPE_CLASSIC | 0 | MIFARE Classic.|
| TYPE_PLUS | 1 | MIFARE Plus.|
| TYPE_PRO | 2 | MIFARE Pro.|
## MifareTagSize9+
| **Name**| **Value**| **Description**|
| -------- | -------- | -------- |
| MC_SIZE_MINI | 320 | Each tag has 5 sectors, and each sector has 4 blocks.|
| MC_SIZE_1K | 1024 | Each tag has 16 sectors, and each sector has 4 blocks.|
| MC_SIZE_2K | 2048 | Each tag has 32 sectors, and each sector has 4 blocks.|
| MC_SIZE_4K | 4096 | Each tag has 40 sectors, and each sector has 4 blocks.|
### MifareClassicTag.isEmulatedTag9+
isEmulatedTag(): boolean
Checks whether the tag is an emulated tag.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC
**Return value**
| **Type**| **Description** |
| ------------------ | --------------------------|
| boolean |Returns **true** if the tag is an emulated tag; returns **false** otherwise.|
**Example**
```js
import tag from '@ohos.nfc.tag';
// tagInfo is an object given by the NFC service when a tag is dispatched.
let isEmulated = tag.MifareClassicTag(taginfo).isEmulatedTag();
```
### MifareClassicTag.getBlockIndex9+
getBlockIndex(sectorIndex: number): number
Obtains the first block of a sector.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | -------------------------------------- |
| sectorIndex | number | Yes | Index of the sector.|
**Return value**
| **Type**| **Description** |
| ------------------ | --------------------------|
| number | Index of the first block obtained.|
**Example**
```js
import tag from '@ohos.nfc.tag';
// tagInfo is an object given by the NFC service when a tag is dispatched.
let index = tag.MifareClassicTag(taginfo).getBlockIndex(sectorIndex);
```
### MifareClassicTag.getSectorIndex9+
getSectorIndex(blockIndex: number): number
Obtains the index of a sector that contains the specified block.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | -------------------------------------- |
| blockIndex | number | Yes | Index of the block contained in the sector.|
**Return value**
| **Type**| **Description** |
| ------------------ | --------------------------|
| number | Index of the sector obtained.|
**Example**
```js
import tag from '@ohos.nfc.tag';
// tagInfo is an object given by the NFC service when a tag is dispatched.
let index = tag.MifareClassicTag(taginfo).getSectorIndex(blockIndex);
```
## MifareUltralightTag9+
Provides access to MIFARE Ultralight properties and I/O operations. This class 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**.
### MifareUltralightTag.readMultiplePages9+
readMultiplePages(pageIndex: number): Promise\
Reads multiple pages (4 bytes per page). This API uses a promise to return the result.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | ------------------------------ |
| pageIndex | number | Yes | Indexes of the pages to read.|
**Return value**
| **Type**| **Description** |
| ------------------ | --------------------------|
| Promise\ | Promise used to return the data read.|
**Example**
```js
import tag from '@ohos.nfc.tag';
// tagInfo is an object given by the NFC service when a tag is dispatched.
tag.MifareUltralightTag(taginfo).readMultiplePages(pageIndex).then(function (data){
console.log("data: " + data)
})
```
### MifareUltralightTag.readMultiplePages9+
readMultiplePages(pageIndex: number, callback: AsyncCallback\): void
Reads multiple pages (4 bytes per page). This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | -------------------------------------- |
| pageIndex | number | Yes | Indexes of the pages to read.|
| callback | AsyncCallback\ | Yes | Callback invoked to return the data read.|
**Example**
```js
import tag from '@ohos.nfc.tag';
// tagInfo is an object given by the NFC service when a tag is dispatched.
tag.MifareUltralightTag(taginfo).readMultiplePages(pageIndex, function (error, data) {
console.log(JSON.stringify(error))
console.log(JSON.stringify(data))
})
```
### MifareUltralightTag.writeSinglePages9+
writeSinglePages(pageIndex: number, data: string): Promise\
Writes a page of data. This API uses a promise to return the result.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | -------------------------------------- |
| pageIndex | number | Yes | Index of the page.|
| data | string | Yes | Data to write.|
**Return value**
| **Type**| **Description** |
| ------------------ | --------------------------|
| Promise\ | 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
import tag from '@ohos.nfc.tag';
// tagInfo is an object given by the NFC service when a tag is dispatched.
tag.MifareUltralightTag(taginfo).writeSinglePages(pageIndex, data).then(function (errcode){
console.log(JSON.stringify(errcode))
})
```
### MifareUltralightTag.writeSinglePages9+
writeSinglePages(pageIndex: number, data: string, callback: AsyncCallback\): void
Writes a page of data. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | ------------------------ |
| pageIndex | number | Yes | Index of the page.|
| data | string | Yes | Data to write.|
| callback|AsyncCallback\ |Yes| Callback invoked to return the result.|
**Example**
```js
import tag from '@ohos.nfc.tag';
// tagInfo is an object given by the NFC service when a tag is dispatched.
tag.MifareUltralightTag(taginfo).writeSinglePages(pageIndex, data, function (error, errcode) {
console.log(JSON.stringify(error))
console.log(JSON.stringify(errcode))
})
```
### MifareUltralightTag.getType9+
getType(): MifareUltralightType
Obtains the MIFARE Ultralight tag type, in bytes.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC
**Return value**
| **Type**| **Description** |
| ------------------ | --------------------------|
| MifareUltralightType | Type of the MIFARE Ultralight tag. For details, see [MifareUltralightType](#mifareultralighttype9).|
**Example**
```js
import tag from '@ohos.nfc.tag';
// tagInfo is an object given by the NFC service when a tag is dispatched.
let type = tag.MifareUltralightType(taginfo).getType();
```
### MifareUltralightType9+
| **Name**| **Value**| **Description**|
| -------- | -------- | -------- |
| TYPE_UNKOWN | -1 | Unknown type.|
| TYPE_ULTRALIGHT | 1 | MIFARE Ultralight.|
| TYPE_ULTRALIGHT_C | 2 | MIFARE Ultralight C.|
## NdefFormatableTag9+
Provides APIs for operating NDEF formattable tags. This class 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**.
### NdefFormatableTag.format9+
format(message: [NdefMessage](#ndefmessage9)): Promise\
Formats this tag as an NDEF tag, and writes an NDEF message to the tag. This API uses a promise to return the result.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | -------------------------------------- |
| message | [NdefMessage](#ndefmessage9) | Yes | NDEF message to write when the formatting is successful. If this parameter is **null**, the tag is formatted only (no data will be written).|
**Return value**
| **Type**| **Description** |
| ------------------ | --------------------------|
| Promise\ | 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
import tag from '@ohos.nfc.tag';
// tagInfo is an object given by the NFC service when a tag is dispatched.
tag.NdefFormatableTag(taginfo).format(message).then(function (errcode){
console.log(JSON.stringify(errcode))
})
```
### NdefFormatableTag.format9+
format(message: [NdefMessage](#ndefmessage9), callback: AsyncCallback\): void
Formats this tag as an NDEF tag, and writes an NDEF message to the tag. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | -------------------------------------- |
| message | [NdefMessage](#ndefmessage9) | Yes | NDEF message to write when the formatting is successful. If this parameter is **null**, the tag is formatted only.|
| callback | AsyncCallback\ |Yes|Callback invoked to return the result.|
**Example**
```js
import tag from '@ohos.nfc.tag';
// tagInfo is an object given by the NFC service when a tag is dispatched.
tag.NdefFormatableTag(taginfo).format(message, function (error, errcode) {
console.log(JSON.stringify(error))
console.log(JSON.stringify(errcode))
})
```
### NdefFormatableTag.formatReadOnly9+
formatReadOnly(message: [NdefMessage](#ndefmessage9)): Promise\
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.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | -------------------------------------- |
| message | [NdefMessage](#ndefmessage9) | Yes | NDEF message to write when the formatting is successful. If this parameter is **null**, the tag is formatted only (no data will be written).|
**Return value**
| **Type**| **Description** |
| ------------------ | --------------------------|
| Promise\ | 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
import tag from '@ohos.nfc.tag';
// tagInfo is an object given by the NFC service when a tag is dispatched.
tag.NdefFormatableTag(taginfo).formatReadOnly(message).then(function (errcode){
console.log(JSON.stringify(errcode))
})
```
### NdefFormatableTag.formatReadOnly9+
formatReadOnly(message: [NdefMessage](#ndefmessage9), callback: AsyncCallback\): void
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.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | -------------------------------------- |
| message | [NdefMessage](#ndefmessage9) | Yes | NDEF message to write when the formatting is successful. If this parameter is **null**, the tag is formatted only.|
| callback | AsyncCallback\ |Yes|Callback invoked to return the result.|
**Example**
```js
import tag from '@ohos.nfc.tag';
// tagInfo is an object given by the NFC service when a tag is dispatched.
tag.NdefFormatableTag(taginfo).formatReadOnly(message, function (error, errcode) {
console.log(JSON.stringify(error))
console.log(JSON.stringify(errcode))
})
```