diff --git a/en/application-dev/reference/apis/js-apis-nfcTag.md b/en/application-dev/reference/apis/js-apis-nfcTag.md
index 5941d465a085a425ef7d10cb28d5fe4b621bc0b2..2f3a208fe1f95b2c4f936709d047fa4c9581f8b6 100644
--- a/en/application-dev/reference/apis/js-apis-nfcTag.md
+++ b/en/application-dev/reference/apis/js-apis-nfcTag.md
@@ -1,19 +1,100 @@
# NFC Tags
-The **nfcTag** module provides methods for managing Near-Field Communication (NFC) tags.
+The **nfcTag** module provides APIs for managing Near-Field Communication (NFC) tags.
> **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.
+## **Declaration**
+
+Before developing applications related to tag read and write, you must declare NFC-related attributes in the attribute configuration file of the applications. For example, declare the following attributes in the **module.json5** file:
+```js
+{
+ "module": {
+ // Attributes to declare.
+
+ "abilities": [
+ {
+ "skills": [
+ {
+ "actions": [
+ // Actions to declare.
+
+ // Add the nfc tag action.
+ "ohos.nfc.tag.action.TAG_FOUND"
+ ]
+ }
+ ],
+ "metadata": [
+ {
+ "name": "tag-tech",
+ "value": "NfcA"
+ },
+ {
+ "name": "tag-tech",
+ "value": "IsoDep"
+ },
+ // Add other technologies,
+ // such as NfcB, NfcF, NfcV, Ndef, MifareClassic, MifareUL, and NdefFormatable.
+ ]
+ }
+ ],
+ "requestPermissions": [
+ "name": "ohos.permission.NFC_TAG",
+ "reason": "tag",
+ ]
+ }
+}
+```
+> **CAUTION**
+>
+> - The **actions** field is mandatory. It must be **ohos.nfc.tag.action.TAG_FOUND** and cannot be changed.
+> - The **name** field of **metadata** is mandatory. It must be **tag-tech** and cannot be changed.
+> - The **value** field of **metadata** is mandatory. It can be **NfcA**, **NfcB**, **NfcF**, **NfcV**, **IsoDep**, **Ndef**, **MifareClassic**, **MifareUL**, **NdefFormatable** or their combinations. Incorrect setting of this field will cause a parsing failure.
+> - The **name** field of **requestPermissions** is mandatory. It must be **ohos.permission.NFC_TAG** and cannot be changed.
+
+
## **Modules to Import**
```js
import tag from '@ohos.nfc.tag';
```
+## **tag.TagInfo**
+Before reading or writing data to a card with tags, the application must obtain **TagInfo** to determine the tag technologies supported by the card. Then, the application can invoke the correct API to communicate with the card.
+```js
+import tag from '@ohos.nfc.tag';
+
+onCreate(want, launchParam) {
+ // Add other code here.
+
+ // want is initialized by the NFC service and contains taginfo.
+ var tagInfo = tag.getTagInfo(want);
+ if (tagInfo == undefined) {
+ console.log("no TagInfo to be created, ignore it.");
+ return;
+ }
+ var isNfcATag = false;
+ for (var i = 0; i < tagInfo.technology.length; i++) {
+ if (tagInfo.technology[i] == tag.NFC_A) {
+ isNfcATag = true;
+ break;
+ }
+ // Also check for technology tag.NFC_B, NFC_F, NFC_V, ISO_DEP, NDEF, MIFARE_CLASSIC, MIFARE_ULTRALIGHT, and NDEF_FORMATABLE.
+ }
+ if (isNfcATag) {
+ var nfcA = tag.getNfcATag(taginfo);
+ // Other code to read or write this tag.
+ }
+
+ // use the same code to handle "NfcA/NfcB/NfcF/NfcV/IsoDep/Ndef/MifareClassic/MifareUL/NdefFormatable", such as,
+ // var isoDep = tag.getIsoDepTag(taginfo);
+}
+```
+
## tag.getNfcATag
-getNfcATag(tagInfo: [TagInfo](#taginfo9)): [NfcATag](js-apis-nfctech.md#nfcatag)
+getNfcATag(tagInfo: [TagInfo](#taginfo)): [NfcATag](js-apis-nfctech.md#nfcatag)
Obtains an **NfcATag** object, which allows access to the tags that use the NFC-A technology.
@@ -29,7 +110,7 @@ Obtains an **NfcATag** object, which allows access to the tags that use the NFC-
## tag.getNfcBTag
-getNfcBTag(tagInfo: [TagInfo](#taginfo9)): [NfcBTag](js-apis-nfctech.md#nfcbtag)
+getNfcBTag(tagInfo: [TagInfo](#taginfo)): [NfcBTag](js-apis-nfctech.md#nfcbtag)
Obtains an **NfcBTag** object, which allows access to the tags that use the NFC-B technology.
@@ -45,7 +126,7 @@ Obtains an **NfcBTag** object, which allows access to the tags that use the NFC-
## tag.getNfcFTag
-getNfcFTag(tagInfo: [TagInfo](#taginfo9)): [NfcFTag](js-apis-nfctech.md#nfcftag)
+getNfcFTag(tagInfo: [TagInfo](#taginfo)): [NfcFTag](js-apis-nfctech.md#nfcftag)
Obtains an **NfcFTag** object, which allows access to the tags that use the NFC-F technology.
@@ -61,7 +142,7 @@ Obtains an **NfcFTag** object, which allows access to the tags that use the NFC-
## tag.getNfcVTag
-getNfcVTag(tagInfo: [TagInfo](#taginfo9)): [NfcVTag](js-apis-nfctech.md#nfcvtag)
+getNfcVTag(tagInfo: [TagInfo](#taginfo)): [NfcVTag](js-apis-nfctech.md#nfcvtag)
Obtains an **NfcVTag** object, which allows access to the tags that use the NFC-V technology.
@@ -77,11 +158,10 @@ Obtains an **NfcVTag** object, which allows access to the tags that use the NFC-
## tag.getIsoDepTag9+
-getIsoDepTag(tagInfo: [TagInfo](#taginfo9)): [IsoDepTag](js-apis-nfctech.md#isodeptag9 )
+getIsoDepTag(tagInfo: [TagInfo](#taginfo)): [IsoDepTag](js-apis-nfctech.md#isoDepTag9 )
Obtains an **IsoDepTag** object, which allows access to the tags that use the ISO-DEP technology.
-
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Core
@@ -94,7 +174,7 @@ Obtains an **IsoDepTag** object, which allows access to the tags that use the IS
## tag.getNdefTag9+
-getNdefTag(tagInfo: [TagInfo](#taginfo9)): [NdefTag](js-apis-nfctech.md#ndeftag9)
+getNdefTag(tagInfo: [TagInfo](#taginfo)): [NdefTag](js-apis-nfctech.md#ndeftag9)
Obtains an **NdefTag** object, which allows access to the tags in the NFC Data Exchange Format (NDEF).
@@ -111,7 +191,7 @@ Obtains an **NdefTag** object, which allows access to the tags in the NFC Data E
## tag.getMifareClassicTag9+
-getMifareClassicTag(tagInfo: [TagInfo](#taginfo9)): [MifareClassicTag](js-apis-nfctech.md#mifareclassictag-9)
+getMifareClassicTag(tagInfo: [TagInfo](#taginfo)): [MifareClassicTag](js-apis-nfctech.md#mifareclassictag-9)
Obtains a **MifareClassicTag** object, which allows access to the tags that use MIFARE Classic.
@@ -127,7 +207,7 @@ Obtains a **MifareClassicTag** object, which allows access to the tags that use
## tag.getMifareUltralightTag9+
-getMifareUltralightTag(tagInfo: [TagInfo](#taginfo9)): [MifareUltralightTag](js-apis-nfctech.md#mifareultralighttag9)
+getMifareUltralightTag(tagInfo: [TagInfo](#taginfo)): [MifareUltralightTag](js-apis-nfctech.md#mifareultralighttag9)
Obtains a **MifareUltralightTag** object, which allows access to the tags that use MIFARE Ultralight.
@@ -143,7 +223,7 @@ Obtains a **MifareUltralightTag** object, which allows access to the tags that u
## tag.getNdefFormatableTag9+
-getNdefFormatableTag(tagInfo: [TagInfo](#taginfo9)): [NdefFormatableTag](js-apis-nfctech.md#ndefformatabletag9)
+getNdefFormatableTag(tagInfo: [TagInfo](#taginfo)): [NdefFormatableTag](js-apis-nfctech.md#ndefformatabletag9)
Obtains an **NdefFormatableTag** object, which allows access to the tags that are NDEF formattable.
@@ -157,15 +237,143 @@ Obtains an **NdefFormatableTag** object, which allows access to the tags that ar
| ------------------ | --------------------------|
| [NdefFormatableTag](js-apis-nfctech.md#ndefformatabletag) | **NdefFormatableTag** object obtained.|
-## TagInfo9+
+## tag.getTagInfo9+
+
+getTagInfo(want: Want): [TagInfo](#taginfo)
+
+Obtains **TagInfo** from **Want**, which is initialized by the NFC service and contains the attributes required by **TagInfo**.
+
+**Required permissions**: ohos.permission.NFC_TAG
+
+**System capability**: SystemCapability.Communication.NFC.Core
+
+**Return value**
+
+| **Type**| **Description** |
+| ------------------ | --------------------------|
+| [TagInfo](#taginfo) | **TagInfo** object obtained.|
+
+## TagInfo
+
+Defines the **TagInfo** object, which provides information about the tag technologies supported by a card.
-Represents the NFC tag information.
+**Required permissions**: ohos.permission.NFC_TAG
+
+**System capability**: SystemCapability.Communication.NFC.Core
| **Name**| **Type**| **Description**|
| -------- | -------- | -------- |
-| uid | string | UID of the tag.|
-| technology | number[] | Technology supported by the tag.|
-| extrasData | PacMap[] | Additional information about the tag.|
-| tagRfDiscId | number | RF discovery ID of the tag.|
-| remoteTagService | rpc.RemoteObject | RPC remote object of the tag service.|
-| supportedProfiles | number[] | Profiles supported by the tag.|
+| uid9+ | number[] | Tag unique identifier (UID). Each number of the UID is a hexadecimal number ranging from **0x00** to **0xFF**.|
+| technology9+ | number[] | Supported technologies. Each number is a constant indicating the supported technology.|
+| supportedProfiles | number[] | Supported technologies. This parameter is not supported since API version 9 and is replaced by **technology**.|
+
+## NdefRecord9+
+Defines an NDEF tag record. For details, see *NFCForum-TS-NDEF_1.0*.
+
+**Required permissions**: ohos.permission.NFC_TAG
+
+**System capability**: SystemCapability.Communication.NFC.Core
+| **Name**| **Type**| **Description**|
+| -------- | -------- | -------- |
+| tnf | number | Type name field (TNF) of an NDEF record.|
+| rtdType| number[] | Record type definition (RTD) of an NDEF record. Each number is a hexadecimal number ranging from **0x00** to **0xFF**.|
+| id | number[] | ID of an NDEF record. Each number is a hexadecimal number ranging from **0x00** to **0xFF**.|
+| payload | number[] | Payload of an NDEF record. Each number is a hexadecimal number ranging from **0x00** to **0xFF**.|
+
+## Technology Type Definition
+Enumerates the tag technology types.
+
+**Required permissions**: ohos.permission.NFC_TAG
+
+**System capability**: SystemCapability.Communication.NFC.Core
+| **Name**| **Value**| **Description**|
+| -------- | -------- | -------- |
+| NFC_A | 1 | NFC-A (ISO 14443-3A).|
+| NFC_B | 2 | NFC-A (ISO 14443-3B).|
+| ISO_DEP | 3 | ISO-DEP (ISO 14443-4).|
+| NFC_F | 4 | NFC-F (JIS 6319-4).|
+| NFC_V | 5 | NFC-V (ISO 15693).|
+| NDEF | 6 | NDEF.|
+| MIFARE_CLASSIC | 8 | MIFARE Classic.|
+| MIFARE_ULTRALIGHT | 9 | MIFARE Ultralight.|
+| NDEF_FORMATABLE9+ | 10 | NDEF formattable.|
+
+## TnfType9+
+Enumerates the TNF types. For details, see *NFCForum-TS-NDEF_1.0*.
+
+**Required permissions**: ohos.permission.NFC_TAG
+
+**System capability**: SystemCapability.Communication.NFC.Core
+| **Name**| **Value**| **Description**|
+| -------- | -------- | -------- |
+| TNF_EMPTY | 0x0 | Empty.|
+| TNF_WELL_KNOWN | 0x01 | NFC Forum Well Known Type [NFC RTD].|
+| TNF_MEDIA | 0x02 | Media-type as defined in RFC 2046 [RFC 2046].|
+| TNF_ABSOLUTE_URI | 0x03 | Absolute URI as defined in RFC 3986 [RFC 3986].|
+| TNF_EXT_APP | 0x04 | NFC Forum external type [NFC RTD].|
+| TNF_UNKNOWN | 0x05 | Unknown.|
+| TNF_UNCHANGED | 0x06 | Unchanged (see section 2.3.3).|
+
+## NDEF Record RTD
+Enumerates the NDEF record types. For details about the RTD, see *NFCForum-TS-NDEF_1.0*.
+
+**Required permissions**: ohos.permission.NFC_TAG
+
+**System capability**: SystemCapability.Communication.NFC.Core
+| **Name**| **Value**| **Description**|
+| -------- | -------- | -------- |
+| RTD_TEXT9+ | [0x54] | NDEF record of the text type.|
+| RTD_URI9+ | [0x55] | NDEF record of the URI type.|
+
+## NfcForumType9+
+Enumerates the NFC Forum tag types.
+
+**Required permissions**: ohos.permission.NFC_TAG
+
+**System capability**: SystemCapability.Communication.NFC.Core
+| **Name**| **Value**| **Description**|
+| -------- | -------- | -------- |
+| NFC_FORUM_TYPE_1 | 1 | NFC Forum tag type 1.|
+| NFC_FORUM_TYPE_2 | 2 | NFC Forum tag type 2.|
+| NFC_FORUM_TYPE_3 | 3 | NFC Forum tag type 3.|
+| NFC_FORUM_TYPE_4 | 4 | NFC Forum tag type 4.|
+| MIFARE_CLASSIC | 101 | MIFARE Classic type.|
+
+## MifareClassicType9+
+Enumerates the MIFARE Classic tag types.
+
+**Required permissions**: ohos.permission.NFC_TAG
+
+**System capability**: SystemCapability.Communication.NFC.Core
+| **Name**| **Value**| **Description**|
+| -------- | -------- | -------- |
+| TYPE_UNKNOWN | -1 | Unknown type.|
+| TYPE_CLASSIC | 0 | MIFARE Classic.|
+| TYPE_PLUS | 1 | MIFARE Plus.|
+| TYPE_PRO | 2 | MIFARE Pro.|
+
+## MifareClassicSize9+
+Enumerates the storage sizes of MIFARE Classic tags.
+
+**Required permissions**: ohos.permission.NFC_TAG
+
+**System capability**: SystemCapability.Communication.NFC.Core
+| **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.|
+
+### MifareUltralightType9+
+Enumerates the MIFARE Ultralight tag types.
+
+**Required permissions**: ohos.permission.NFC_TAG
+
+**System capability**: SystemCapability.Communication.NFC.Core
+| **Name**| **Value**| **Description**|
+| -------- | -------- | -------- |
+| TYPE_UNKOWN | -1 | Unknown type.|
+| TYPE_ULTRALIGHT | 1 | MIFARE Ultralight.|
+| TYPE_ULTRALIGHT_C | 2 | MIFARE Ultralight C.|
+
diff --git a/en/application-dev/reference/apis/js-apis-nfctech.md b/en/application-dev/reference/apis/js-apis-nfctech.md
index d471510aeec29a3fce389284a54866a55b1ca507..9817e5fd5c1f2a7f797f2c20fa7b6eff18dc25a5 100644
--- a/en/application-dev/reference/apis/js-apis-nfctech.md
+++ b/en/application-dev/reference/apis/js-apis-nfctech.md
@@ -33,16 +33,17 @@ Obtains the SAK value of this NFC-A tag.
| **Type**| **Description** |
| ------------------ | --------------------------|
-| number | SAK value obtained.|
+| number | SAK value obtained. The SAK is a hexadecimal number ranging from **0x00** to **0xFF**.|
**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);
+// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'nfcA' correctly.
+
+let sak = nfcA.getSak();
+console.log("nfcA sak: " + sak);
```
### NfcATag.getAtqa
@@ -59,16 +60,16 @@ Obtains the ATQA value of this NFC-A tag.
| **Type**| **Description** |
| ------------------ | --------------------------|
-| number[] | ATQA value obtained.|
+| number[] | ATQA value obtained. Each number of the ATQA is a hexadecimal number ranging from **0x00** to **0xFF**.|
**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);
+// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'nfcA' correctly.
+let atqa = nfcA.getAtqa();
+console.log("nfcA atqa: " + atqa);
```
## NfcBTag
@@ -93,16 +94,16 @@ Obtains the application data of this NFC-B tag.
| **Type**| **Description** |
| ------------------ | --------------------------|
-| number[] | Application data obtained.|
+| number[] | Application data obtained. Each number in the return result is a hexadecimal number ranging from **0x00** to **0xFF**.|
**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);
+// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'nfcB' correctly.
+let respAppData = nfcB.getRespAppData();
+console.log("nfcB respAppData: " + respAppData);
```
### NfcBTag.getRespProtocol
@@ -119,16 +120,16 @@ Obtains the protocol information of this NFC-B tag.
| **Type**| **Description** |
| ------------------ | --------------------------|
-| number[] | Protocol information obtained.|
+| number[] | Protocol information obtained. Each number in the return result is a hexadecimal number ranging from **0x00** to **0xFF**.|
**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);
+// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'nfcB' correctly.
+let respProtocol = nfcB.getRespProtocol();
+console.log("nfcB respProtocol: " + respProtocol);
```
## NfcFTag
@@ -153,16 +154,16 @@ Obtains the system code from this NFC-F tag.
| **Type**| **Description** |
| ------------------ | --------------------------|
-| number[] | System code obtained.|
+| number[] | System code obtained. Each number in the system code is a hexadecimal number ranging from **0x00** to **0xFF**.|
**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);
+// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'nfcF' correctly.
+let systemCode = nfcF.getSystemCode();
+console.log("nfcF systemCode: " + systemCode);
```
### NfcFTag.getPmm
@@ -179,16 +180,16 @@ Obtains the PMm (consisting of the IC code and manufacturer parameters) informat
| **Type**| **Description** |
| ------------------ | --------------------------|
-| number[] | PMm information obtained.|
+| number[] | PMm information obtained. Each number in the return result is a hexadecimal number ranging from **0x00** to **0xFF**.|
**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);
+// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'nfcF' correctly.
+let pmm = nfcF.getPmm();
+console.log("nfcF pmm: " + pmm);
```
## NfcVTag
@@ -213,16 +214,16 @@ Obtains the response flags from this NFC-V tag.
| **Type**| **Description** |
| ------------------ | --------------------------|
-| number | Response flags obtained.|
+| number | Response flags obtained. The value is a hexadecimal number ranging from **0x00** to **0xFF**.|
**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);
+// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'nfcV' correctly.
+let responseFlags = nfcV.getResponseFlags();
+console.log("nfcV responseFlags: " + responseFlags);
```
### NfcvTag.getDsfId
@@ -239,16 +240,16 @@ Obtains the data storage format identifier (DSFID) from this NFC-V tag.
| **Type**| **Description** |
| ------------------ | --------------------------|
-| number | DSFID obtained.|
+| number | DSFID obtained. The value is a hexadecimal number ranging from **0x00** to **0xFF**.|
**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);
+// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'nfcV' correctly.
+let dsfId = nfcV.getDsfId();
+console.log("nfcV dsfId: " + dsfId);
```
## IsoDepTag9+
@@ -261,7 +262,7 @@ The following describes the unique interfaces of **IsoDepTag**.
### IsoDepTag.getHistoricalBytes9+
-getHistoricalBytes(): string
+getHistoricalBytes(): number[]
Obtains the historical bytes of this tag.
@@ -273,21 +274,21 @@ Obtains the historical bytes of this tag.
| **Type**| **Description** |
| ------------------ | --------------------------|
-| string | Historical bytes obtained.|
+| number[] | Historical bytes obtained. Each number in the return result is a hexadecimal number ranging from **0x00** to **0xFF**.|
**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);
+// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'isoDep' correctly.
+let historicalBytes = isoDep.getHistoricalBytes();
+console.log("isoDep historicalBytes: " + historicalBytes);
```
### IsoDepTag.getHiLayerResponse9+
-getHiLayerResponse(): string
+getHiLayerResponse(): number[]
Obtains the HiLayer response of this tag.
@@ -299,16 +300,16 @@ Obtains the HiLayer response of this tag.
| **Type**| **Description** |
| ------------------ | --------------------------|
-| string | HiLayer response obtained.|
+| number[] | HiLayer response obtained. Each number in the return result is a hexadecimal number ranging from **0x00** to **0xFF**.|
**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);
+// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'isoDep' correctly.
+let hiLayerResponse = isoDep.getHiLayerResponse();
+console.log("isoDep hiLayerResponse: " + hiLayerResponse);
```
### IsoDepTag.isExtendedApduSupported9+
@@ -332,10 +333,13 @@ Checks whether an extended application protocol data unit (APDU) is supported. T
```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)
-})
+// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'isoDep' correctly.
+isoDep.isExtendedApduSupported()
+ .then((data) => {
+ console.log("isoDep isExtendedApduSupported data: " + data);
+ }).catch((err)=> {
+ console.log("isoDep isExtendedApduSupported err: " + err);
+ });
```
### IsoDepTag.isExtendedApduSupported9+
@@ -357,11 +361,14 @@ Checks whether an extended APDU is supported. This API uses an asynchronous call
```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)
-})
+// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'isoDep' correctly.
+isoDep.isExtendedApduSupported((err, data)=> {
+ if (err) {
+ console.log("isoDep isExtendedApduSupported err: " + err);
+ } else {
+ console.log("isoDep isExtendedApduSupported data: " + data);
+ }
+});
```
## NdefTag9+
@@ -374,7 +381,7 @@ The following describes the unique interfaces of **NdefTag**.
### NdefTag.createNdefMessage9+
-createNdefMessage(data: string): [NdefMessage](#ndefmessage9)
+createNdefMessage(data: number[]): [NdefMessage](#ndefmessage9)
Creates an NDEF message using raw bytes.
@@ -386,28 +393,30 @@ Creates an NDEF message using raw bytes.
| **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- |
-| data | string | Yes| Raw bytes of the string type.|
+| data | number[] | Yes| Raw bytes used to create the message. Each number is a hexadecimal number ranging from **0x00** to **0xFF**.|
**Return value**
| **Type**| **Description** |
| ------------------ | --------------------------|
-| [NdefMessage](#ndefmessage9) | NDEF message created.|
+| [NdefMessage](#ndefmessage9) | NDEF message created. For details, see *NFCForum-TS-NDEF_1.0*.|
**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);
+// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'ndef' correctly.
+let rawData = [0x00, 0xa4, 0x04, ......]; // change the raw data bytes tobe correct.
+let ndefMessage = ndef.createNdefMessage(rawData);
+console.log("ndef ndefMessage: " + ndefMessage);
```
## NdefMessage9+
### NdefMessage.getNdefRecords9+
-getNdefRecords(): [NdefRecord](#ndefrecord9)[ ]
+getNdefRecords(): [NdefRecord](js-apis-nfcTag.md#ndefrecord9)[ ]
Obtains all NDEF records.
@@ -419,33 +428,18 @@ Obtains all NDEF records.
| **Type**| **Description** |
| ------------------ | --------------------------|
-| [NdefRecord](#ndefrecord9)[ ] | All records obtained.|
+| [NdefRecord](js-apis-nfcTag.md#ndefrecord9)[ ] | List of NDEF records obtained. For details, see *NFCForum-TS-NDEF_1.0*.|
**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();
+// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'ndef' correctly.
+let ndefRecords = ndef.getNdefRecords();
+console.log("ndef ndefRecords number: " + ndefRecords.length);
```
-## 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)
@@ -459,21 +453,32 @@ Creates an NDEF message using the NDEF records.
**Parameters**
| **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- |
-| ndefRecords | [NdefRecord](#ndefrecord9)[] | Yes| A list of NDEF records.|
+| ndefRecords | [NdefRecord](js-apis-nfcTag.md#ndefrecord9)[] | Yes| NDEF records used to create the NDEF message. For details, see *NFCForum-TS-NDEF_1.0*.|
**Return value**
| **Type**| **Description** |
| ------------------ | --------------------------|
-| [NdefMessage](#ndefmessage9) | NDEF message created.|
+| [NdefMessage](#ndefmessage9) | NDEF message created. For details, see *NFCForum-TS-NDEF_1.0*.|
**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);
+// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'ndef' correctly.
+let ndefRecords = [
+ // record format: tnf, rtdType, id, payload
+ // 1st record:
+ {tnf: 0x01, rtdType: [0x54], id: [0x01, 0x02, ...], payload: [0x00, 0xa4, 0x04, ...]},
+
+ // 2nd record:
+ {tnf: 0x02, rtdType: [0x55], id: [0x03, 0x04, ...], payload: [0x00, 0xa4, 0x04, ...]},
+
+ // other record if has one ...
+];
+let ndefMessage = ndef.createNdefMessage(ndefRecords);
+console.log("ndef ndefMessage: " + ndefMessage);
```
### NdefTag.getNdefTagType9+
@@ -490,22 +495,23 @@ Obtains the type of this NDEF tag.
| **Type**| **Description** |
| ------------------ | --------------------------|
-| [NfcForumType](#nfcforumtype9) | NDEF tag type obtained.|
+| [NfcForumType](js-apis-nfcTag.md#nfcforumtype9) | NDEF tag type obtained. It can be NFC FORUM TYPE 1, 2, 3, or 4.|
**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();
+// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'ndef' correctly.
+let ndefTagType = ndef.getNdefTagType();
+console.log("ndef ndefTagType: " + ndefTagType);
```
### NdefTag.getNdefMessage9+
getNdefMessage(): NdefMessage
-Obtains the NDEF message from the tag discovered.
+Obtains the NDEF message.
**Required permissions**: ohos.permission.NFC_TAG
@@ -515,15 +521,16 @@ Obtains the NDEF message from the tag discovered.
| **Type**| **Description** |
| ------------------ | --------------------------|
-| [NdefMessage](#ndefmessage9) | NDEF message created.|
+| [NdefMessage](#ndefmessage9) | NDEF message obtained. For details, see *NFCForum-TS-NDEF_1.0*.|
**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();
+// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'ndef' correctly.
+let ndefMessage = ndef.getNdefMessage();
+console.log("ndef ndefMessage: " + ndefMessage);
```
### NdefTag.isNdefWritable9+
@@ -547,10 +554,13 @@ Checks whether the NDEF tag is writable. This API uses a promise to return the r
```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))
-})
+// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'ndef' correctly.
+ndef.isNdefWritable()
+ .then((data) => {
+ console.log("ndef isNdefWritable data: " + data);
+ }).catch((err)=> {
+ console.log("ndef isNdefWritable err: " + err);
+ });
```
### NdefTag.isNdefWritable9+
@@ -574,11 +584,14 @@ Checks whether the NDEF tag is writable. This API uses an asynchronous callback
```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)
-})
+// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'ndef' correctly.
+ndef.isNdefWritable((err, data)=> {
+ if (err) {
+ console.log("ndef isNdefWritable err: " + err);
+ } else {
+ console.log("ndef isNdefWritable data: " + data);
+ }
+});
```
### NdefTag.readNdef9+
@@ -595,17 +608,20 @@ Reads the NDEF message from this tag. This API uses a promise to return the resu
| **Type**| **Description** |
| ------------------ | --------------------------|
-| Promise\<[NdefMessage](#ndefmessage9)> | Promise used to return the NDEF message read.|
+| Promise\<[NdefMessage](#ndefmessage9)> | Promise used to return the 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))
-})
+// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'ndef' correctly.
+ndef.readNdef()
+ .then((data) => {
+ console.log("ndef readNdef data: " + data);
+ }).catch((err)=> {
+ console.log("ndef readNdef err: " + err);
+ });
```
### NdefTag.readNdef9+
@@ -629,11 +645,14 @@ Reads the NDEF message from this tag. This API uses an asynchronous callback to
```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)
-})
+// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'ndef' correctly.
+ndef.readNdef((err, data)=> {
+ if (err) {
+ console.log("ndef readNdef err: " + err);
+ } else {
+ console.log("ndef readNdef data: " + data);
+ }
+});
```
### NdefTag.writeNdef9+
@@ -663,10 +682,15 @@ Writes an NDEF message to this tag. This API uses a promise to return the result
```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))
-})
+// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'ndef' correctly.
+let ndefMessage = ndef.createNdefMessage([0x01, 0x02, ...]); // change the raw data to be correct.
+
+ndef.writeNdef(ndefMessage)
+ .then((data) => {
+ console.log("ndef writeNdef data: " + data);
+ }).catch((err)=> {
+ console.log("ndef writeNdef err: " + err);
+ });
```
### NdefTag.writeNdef9+
@@ -691,18 +715,22 @@ Writes an NDEF message to this tag. This API uses an asynchronous callback to re
```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)
-})
+// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'ndef' correctly.
+let ndefMessage = ndef.createNdefMessage([0x01, 0x02, ...]); // change the raw data to be correct.
+ndef.writeNdef(ndefMessage, (err, data)=> {
+ if (err) {
+ console.log("ndef writeNdef err: " + err);
+ } else {
+ console.log("ndef writeNdef data: " + data);
+ }
+});
```
### NdefTag.canSetReadOnly9+
-canSetReadOnly(): Promise\
+canSetReadOnly(): boolean
-Checks whether this NDEF tag can be set to read-only. This API uses a promise to return the result.
+Checks whether this NDEF tag can be set to read-only.
**Required permissions**: ohos.permission.NFC_TAG
@@ -712,45 +740,16 @@ Checks whether this NDEF tag can be set to read-only. This API uses a promise to
| **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.|
+| boolean| Returns **true** if the tag can be set to read-only; 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.
-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)
-})
+// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'ndef' correctly.
+var canSetReadOnly = ndef.canSetReadOnly();
+console.log("ndef canSetReadOnly: " + canSetReadOnly);
```
### NdefTag.setReadOnly9+
@@ -774,15 +773,18 @@ Sets this NDEF tag to read-only. This API uses a promise to return the result.
```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))
-})
+// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'ndef' correctly.
+ndef.setReadOnly()
+ .then((data) => {
+ console.log("ndef setReadOnly data: " + data);
+ }).catch((err)=> {
+ console.log("ndef setReadOnly err: " + err);
+ });
```
### NdefTag.setReadOnly9+
-setReadOnly(callback: AsyncCallback): void
+setReadOnly(callback: AsyncCallback\): void
Sets this NDEF tag to read-only. This API uses an asynchronous callback to return the result.
@@ -801,18 +803,21 @@ Sets this NDEF tag to read-only. This API uses an asynchronous callback to retur
```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)
-})
+// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'ndef' correctly.
+ndef.setReadOnly((err, data)=> {
+ if (err) {
+ console.log("ndef setReadOnly err: " + err);
+ } else {
+ console.log("ndef setReadOnly data: " + data);
+ }
+});
```
### NdefTag.getNdefTagTypeString9+
-getNdefTagTypeString(type: [NfcForumType](#nfcforumtype9)): string
+getNdefTagTypeString(type: [NfcForumType](js-apis-nfcTag.md#nfcforumtype9)): string
-Converts an NFC Forum Type to a byte array defined in the NFC Forum.
+Converts an NFC Forum Type tag to a byte array defined in the NFC Forum.
**Required permissions**: ohos.permission.NFC_TAG
@@ -822,7 +827,7 @@ Converts an NFC Forum Type to a byte array defined in the NFC Forum.
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | -------------------------------------- |
-| type | [NfcForumType](#nfcforumtype9) | Yes | NFC Forum Type.|
+| type | [NfcForumType](js-apis-nfcTag.md#nfcforumtype9) | Yes | NDEF tag type. It can be NFC FORUM type 1, 2, 3, or 4.|
**Return value**
@@ -835,21 +840,12 @@ Converts an NFC Forum Type to a byte array defined in the NFC Forum.
```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);
+// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'ndef' correctly.
+let ndefTypeString = ndef.getNdefTagTypeString(tag.NFC_FORUM_TYPE_1);
+console.log("ndef ndefTypeString: " + ndefTypeString);
```
-## 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+
+## MifareClassicTag9+
Provides access to MIFARE Classic properties and I/O operations. This class inherits from **TagSession**.
@@ -886,15 +882,20 @@ Authenticates a sector using the key. The sector can be accessed only after the
```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))
- })
+// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'mifareClassic' correctly.
+let sectorIndex = 1; // change it to be correct index.
+let key = [0x04, 0x05, ....]; // change it to be correct key.
+mifareClassic.authenticateSector(sectorIndex, key, true);
+ .then((data) => {
+ console.log("mifareClassic authenticateSector data: " + data);
+ }).catch((err)=> {
+ console.log("mifareClassic authenticateSector err: " + err);
+ });
```
### MifareClassicTag.authenticateSector9+
-authenticateSector(sectorIndex: number, key: number[], isKeyA: boolean, callback: AsyncCallback): void
+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.
@@ -916,16 +917,21 @@ Authenticates a sector using the key. The sector can be accessed only after the
```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)
-})
+// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'mifareClassic' correctly.
+let sectorIndex = 1; // change it to be correct index.
+let key = [0x04, 0x05, ....]; // change it to be correct key.
+mifareClassic.authenticateSector(sectorIndex, key, true, (err, data)=> {
+ if (err) {
+ console.log("mifareClassic authenticateSector err: " + err);
+ } else {
+ console.log("mifareClassic authenticateSector data: " + data);
+ }
+});
```
### MifareClassicTag.readSingleBlock9+
-readSingleBlock(blockIndex: number): Promise\
+readSingleBlock(blockIndex: number): Promise\
Reads a block (16 bytes) on the tag. This API uses a promise to return the result.
@@ -943,23 +949,27 @@ Reads a block (16 bytes) on the tag. This API uses a promise to return the resul
| **Type**| **Description** |
| ------------------ | --------------------------|
-| Promise\ | Promise used to return the block data read.|
+| 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)
- })
+// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'mifareClassic' correctly.
+let blockIndex = 1; // change it to be correct index.
+mifareClassic.readSingleBlock(blockIndex, (err, data)=> {
+ if (err) {
+ console.log("mifareClassic readSingleBlock err: " + err);
+ } else {
+ console.log("mifareClassic readSingleBlock data: " + data);
+ }
+});
```
### MifareClassicTag.readSingleBlock9+
-readSingleBlock(blockIndex: number, callback: AsyncCallback\): void
+readSingleBlock(blockIndex: number, callback: AsyncCallback\): void
Reads a block (16 bytes) on the tag. This API uses an asynchronous callback to return the result.
@@ -972,24 +982,27 @@ Reads a block (16 bytes) on the tag. This API uses an asynchronous callback to r
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | -------------------------------------- |
| blockIndex | number | Yes | Index of the block to read.|
-| callback | AsyncCallback\ | Yes | Callback invoked to return the block 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)
-})
+// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'mifareClassic' correctly.
+let blockIndex = 1; // change it to be correct index.
+mifareClassic.readSingleBlock(blockIndex, (err, data)=> {
+ if (err) {
+ console.log("mifareClassic readSingleBlock err: " + err);
+ } else {
+ console.log("mifareClassic readSingleBlock data: " + data);
+ }
+});
```
### MifareClassicTag.writeSingleBlock9+
-writeSingleBlock(blockIndex: number, data: string): Promise\
+writeSingleBlock(blockIndex: number, data: number[]): Promise\
Writes data to a block on the tag. This API uses a promise to return the result.
@@ -1002,7 +1015,7 @@ Writes data to a block on the tag. This API uses a promise to return the result.
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | -------------------------------------- |
| blockIndex | number | Yes | Index of the target block.|
-| data | string | Yes | Data to write.|
+| data | number[] | Yes | Data to write.|
**Return value**
@@ -1015,16 +1028,21 @@ Writes data to a block on the tag. This API uses a promise to return the result.
```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))
- })
+// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'mifareClassic' correctly.
+let blockIndex = 1; // change it to be correct index.
+let rawData = [0x0a, 0x14, ...]; // change it to be correct data.
+mifareClassic.writeSingleBlock(blockIndex, rawData, (err, data)=> {
+ if (err) {
+ console.log("mifareClassic writeSingleBlock err: " + err);
+ } else {
+ console.log("mifareClassic writeSingleBlock data: " + data);
+ }
+});
```
### MifareClassicTag.writeSingleBlock9+
-writeSingleBlock(blockIndex: number, data: string, callback: AsyncCallback\): void
+writeSingleBlock(blockIndex: number, data: number[], callback: AsyncCallback\): void
Writes data to a block on the tag. This API uses an asynchronous callback to return the result.
@@ -1037,7 +1055,7 @@ Writes data to a block on the tag. This API uses an asynchronous callback to ret
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | -------------------------------------- |
| blockIndex | number | Yes | Index of the target block.|
-| data | string | Yes | Data to write.|
+| data | number[] | Yes | Data to write.|
| callback | AsyncCallback\ | Yes | Callback invoked to return the result.|
**Example**
@@ -1045,12 +1063,16 @@ Writes data to a block on the tag. This API uses an asynchronous callback to ret
```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))
-})
+// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'mifareClassic' correctly.
+let blockIndex = 1; // change it to be correct index.
+let rawData = [0x0a, 0x14, ...]; // change it to be correct data.
+mifareClassic.writeSingleBlock(blockIndex, rawData, (err, data)=> {
+ if (err) {
+ console.log("mifareClassic writeSingleBlock err: " + err);
+ } else {
+ console.log("mifareClassic writeSingleBlock data: " + data);
+ }
+});
```
### MifareClassicTag.incrementBlock9+
@@ -1081,10 +1103,16 @@ Increments a block with data. This API uses a promise to return the result.
```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))
- })
+// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'mifareClassic' correctly.
+let blockIndex = 1; // change it to be correct index.
+let value = 0x20; // change it to be correct data.
+mifareClassic.incrementBlock(blockIndex, value, (err, data)=> {
+ if (err) {
+ console.log("mifareClassic incrementBlock err: " + err);
+ } else {
+ console.log("mifareClassic incrementBlock data: " + data);
+ }
+});
```
### MifareClassicTag.incrementBlock9+
@@ -1110,11 +1138,16 @@ Increments a block with data. This API uses an asynchronous callback to return t
```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))
-})
+// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'mifareClassic' correctly.
+let blockIndex = 1; // change it to be correct index.
+let value = 0x20; // change it to be correct data.
+mifareClassic.incrementBlock(blockIndex, value, (err, data)=> {
+ if (err) {
+ console.log("mifareClassic incrementBlock err: " + err);
+ } else {
+ console.log("mifareClassic incrementBlock data: " + data);
+ }
+});
```
### MifareClassicTag.decrementBlock9+
@@ -1145,10 +1178,16 @@ Decrements a block with data. This API uses a promise to return the result.
```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))
- })
+// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'mifareClassic' correctly.
+let blockIndex = 1; // change it to be correct index.
+let value = 0x20; // change it to be correct data.
+mifareClassic.decrementBlock(blockIndex, value, (err, data)=> {
+ if (err) {
+ console.log("mifareClassic decrementBlock err: " + err);
+ } else {
+ console.log("mifareClassic decrementBlock data: " + data);
+ }
+});
```
### MifareClassicTag.decrementBlock9+
@@ -1174,11 +1213,16 @@ Decrements a block with data. This API uses an asynchronous callback to return t
```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))
-})
+// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'mifareClassic' correctly.
+let blockIndex = 1; // change it to be correct index.
+let value = 0x20; // change it to be correct data.
+mifareClassic.decrementBlock(blockIndex, value, (err, data)=> {
+ if (err) {
+ console.log("mifareClassic decrementBlock err: " + err);
+ } else {
+ console.log("mifareClassic decrementBlock data: " + data);
+ }
+});
```
### MifareClassicTag.transferToBlock9+
@@ -1209,13 +1253,18 @@ Copies data from the register to a block. This API uses a promise to return the
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))
- })
+// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'mifareClassic' correctly.
+let blockIndex = 1; // change it to be correct index.
+mifareClassic.transferToBlock(blockIndex, (err, data)=> {
+ if (err) {
+ console.log("mifareClassic transferToBlock err: " + err);
+ } else {
+ console.log("mifareClassic transferToBlock data: " + data);
+ }
+});
```
-### MifareClassicTag.transferToBlock
+### MifareClassicTag.transferToBlock9+
transferToBlock(blockIndex: number, callback: AsyncCallback\): void
@@ -1237,11 +1286,15 @@ Copies data from the register to a block. This API uses an asynchronous callback
```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))
-})
+// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'mifareClassic' correctly.
+let blockIndex = 1; // change it to be correct index.
+mifareClassic.transferToBlock(blockIndex, (err, data)=> {
+ if (err) {
+ console.log("mifareClassic transferToBlock err: " + err);
+ } else {
+ console.log("mifareClassic transferToBlock data: " + data);
+ }
+});
```
### MifareClassicTag.restoreFromBlock9+
@@ -1272,10 +1325,14 @@ Copies data from a block to the register. This API uses a promise to return the
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))
- })
+// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'mifareClassic' correctly.
+let blockIndex = 1; // change it to be correct index.
+mifareClassic.restoreFromBlock(blockIndex)
+ .then((data) => {
+ console.log("mifareClassic restoreFromBlock data: " + data);
+ }).catch((err)=> {
+ console.log("mifareClassic isExtendrestoreFromBlockedApduSupported err: " + err);
+ });
```
### MifareClassicTag.restoreFromBlock9+
@@ -1300,11 +1357,15 @@ Copies data from a block to the register. This API uses an asynchronous callback
```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))
-})
+// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'mifareClassic' correctly.
+let blockIndex = 1; // change it to be correct index.
+mifareClassic.restoreFromBlock(blockIndex, (err, data)=> {
+ if (err) {
+ console.log("mifareClassic restoreFromBlock err: " + err);
+ } else {
+ console.log("mifareClassic restoreFromBlock data: " + data);
+ }
+});
```
### MifareClassicTag.getSectorCount9+
@@ -1328,8 +1389,9 @@ Obtains the number of sectors in this MIFARE Classic tag.
```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();
+// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'mifareClassic' correctly.
+let sectorCount = mifareClassic.getSectorCount();
+console.log("mifareClassic sectorCount: " + sectorCount);
```
### MifareClassicTag.getBlockCountInSector9+
@@ -1359,13 +1421,14 @@ Obtains the number of blocks in a sector.
```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);
+// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'mifareClassic' correctly.
+let blockCountInSector = mifareClassic.getBlockCountInSector();
+console.log("mifareClassic blockCountInSector: " + blockCountInSector);
```
### MifareClassicTag.getType9+
-getType(): [MifareClassicType](#mifareclassictype9)
+getType(): [MifareClassicType](js-apis-nfcTag.md#mifareclassictype9)
Obtains the type of this MIFARE Classic tag.
@@ -1377,22 +1440,23 @@ Obtains the type of this MIFARE Classic tag.
| **Type**| **Description** |
| ------------------ | --------------------------|
-| [MifareClassicType](#mifareclassictype9) | Type of the MIFARE Classic tag obtained.|
+| [MifareClassicType](js-apis-nfcTag.md#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();
+// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'mifareClassic' correctly.
+let getType = mifareClassic.getType();
+console.log("mifareClassic getType: " + getType);
```
### MifareClassicTag.getTagSize9+
getTagSize(): number
-Obtains the tag size (in bytes). For details, see [MifareTagSize](#mifaretagsize9).
+Obtains the tag size (in bytes). For details, see [MifareClassicSize](js-apis-nfcTag.md#mifareclassicsize9).
**Required permissions**: ohos.permission.NFC_TAG
@@ -1402,35 +1466,18 @@ Obtains the tag size (in bytes). For details, see [MifareTagSize](#mifaretagsize
| **Type**| **Description** |
| ------------------ | --------------------------|
-| number | Tag size obtained, in bytes. For details, see [MifareTagSize](#mifaretagsize9).|
+| number | Tag size obtained, in bytes. For details, see [MifareClassicSize](js-apis-nfcTag.md#mifareclassicsize9).|
**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();
+// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'mifareClassic' correctly.
+let tagSize = mifareClassic.getTagSize();
+console.log("mifareClassic tagSize: " + tagSize);
```
-## 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
@@ -1452,8 +1499,9 @@ Checks whether the tag is an emulated tag.
```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();
+// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'mifareClassic' correctly.
+let isEmulatedTag = mifareClassic.isEmulatedTag();
+console.log("mifareClassic isEmulatedTag: " + isEmulatedTag);
```
### MifareClassicTag.getBlockIndex9+
@@ -1483,8 +1531,10 @@ Obtains the first block of a sector.
```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);
+// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'mifareClassic' correctly.
+let sectorIndex = 1; // change it to be correct index.
+let blockIndex = mifareClassic.getBlockIndex(sectorIndex);
+console.log("mifareClassic blockIndex: " + blockIndex);
```
### MifareClassicTag.getSectorIndex9+
@@ -1514,8 +1564,10 @@ Obtains the index of a sector that contains the specified block.
```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);
+// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'mifareClassic' correctly.
+let blockIndex = 1; // change it to be correct index.
+let sectorIndex = mifareClassic.getSectorIndex(blockIndex);
+console.log("mifareClassic sectorIndex: " + sectorIndex);
```
## MifareUltralightTag9+
@@ -1528,7 +1580,7 @@ The following describes the unique interfaces of **MifareUltralightTag**.
### MifareUltralightTag.readMultiplePages9+
-readMultiplePages(pageIndex: number): Promise\
+readMultiplePages(pageIndex: number): Promise\
Reads multiple pages (4 bytes per page). This API uses a promise to return the result.
@@ -1546,7 +1598,7 @@ Reads multiple pages (4 bytes per page). This API uses a promise to return the r
| **Type**| **Description** |
| ------------------ | --------------------------|
-| Promise\ | Promise used to return the data read.|
+| Promise\ | Promise used to return the data read.|
**Example**
@@ -1554,15 +1606,19 @@ Reads multiple pages (4 bytes per page). This API uses a promise to return the r
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)
- })
+// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'mifareUltralight' correctly.
+let pageIndex = 1; // change it to be correct index.
+mifareUltralight.readMultiplePages(pageIndex)
+ .then((data) => {
+ console.log("mifareUltralight readMultiplePages data: " + data);
+ }).catch((err)=> {
+ console.log("mifareUltralight readMultiplePages err: " + err);
+ });
```
### MifareUltralightTag.readMultiplePages9+
-readMultiplePages(pageIndex: number, callback: AsyncCallback\): void
+readMultiplePages(pageIndex: number, callback: AsyncCallback\): void
Reads multiple pages (4 bytes per page). This API uses an asynchronous callback to return the result.
@@ -1575,23 +1631,27 @@ Reads multiple pages (4 bytes per page). This API uses an asynchronous callback
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | -------------------------------------- |
| pageIndex | number | Yes | Indexes of the pages to read.|
-| callback | AsyncCallback\ | Yes | Callback invoked to return the data read.|
+| 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).readMultiplePages(pageIndex, function (error, data) {
- console.log(JSON.stringify(error))
- console.log(JSON.stringify(data))
-})
+// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'mifareUltralight' correctly.
+let pageIndex = 1; // change it to be correct index.
+mifareUltralight.readMultiplePages(pageIndex, (err, data)=> {
+ if (err) {
+ console.log("mifareUltralight readMultiplePages err: " + err);
+ } else {
+ console.log("mifareUltralight readMultiplePages data: " + data);
+ }
+});
```
### MifareUltralightTag.writeSinglePages9+
-writeSinglePages(pageIndex: number, data: string): Promise\
+writeSinglePages(pageIndex: number, data: number[]): Promise\
Writes a page of data. This API uses a promise to return the result.
@@ -1604,7 +1664,7 @@ Writes a page of data. This API uses a promise to return the result.
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | -------------------------------------- |
| pageIndex | number | Yes | Index of the page.|
-| data | string | Yes | Data to write.|
+| data | number[] | Yes | Data to write.|
**Return value**
@@ -1617,15 +1677,20 @@ Writes a page of data. This API uses a promise to return the result.
```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))
- })
+// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'mifareUltralight' correctly.
+let pageIndex = 1; // change it to be correct index.
+let data = [0x01, 0x02, ...]; // change it to be correct raw data.
+mifareUltralight.writeSinglePages(pageIndex, data)
+ .then((data) => {
+ console.log("mifareUltralight writeSinglePages data: " + data);
+ }).catch((err)=> {
+ console.log("mifareUltralight writeSinglePages err: " + err);
+ });
```
### MifareUltralightTag.writeSinglePages9+
-writeSinglePages(pageIndex: number, data: string, callback: AsyncCallback\): void
+writeSinglePages(pageIndex: number, data: number[], callback: AsyncCallback\): void
Writes a page of data. This API uses an asynchronous callback to return the result.
@@ -1638,7 +1703,7 @@ Writes a page of data. This API uses an asynchronous callback to return the resu
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | ------------------------ |
| pageIndex | number | Yes | Index of the page.|
-| data | string | Yes | Data to write.|
+| data | number[] | Yes | Data to write.|
| callback|AsyncCallback\ |Yes| Callback invoked to return the result.|
**Example**
@@ -1646,18 +1711,23 @@ Writes a page of data. This API uses an asynchronous callback to return the resu
```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))
-})
+// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'mifareUltralight' correctly.
+let pageIndex = 1; // change it to be correct index.
+let data = [0x01, 0x02, ...]; // change it to be correct raw data.
+mifareUltralight.writeSinglePages(pageIndex, data, (err, data)=> {
+ if (err) {
+ console.log("mifareUltralight writeSinglePages err: " + err);
+ } else {
+ console.log("mifareUltralight writeSinglePages data: " + data);
+ }
+});
```
### MifareUltralightTag.getType9+
getType(): MifareUltralightType
-Obtains the MIFARE Ultralight tag type, in bytes.
+Obtains the MIFARE Ultralight tag type, in bytes. For details, see [MifareUltralightType](js-apis-nfcTag.md#mifareultralighttype9).
**Required permissions**: ohos.permission.NFC_TAG
@@ -1667,25 +1737,18 @@ Obtains the MIFARE Ultralight tag type, in bytes.
| **Type**| **Description** |
| ------------------ | --------------------------|
-| MifareUltralightType | Type of the MIFARE Ultralight tag. For details, see [MifareUltralightType](#mifareultralighttype9).|
+| MifareUltralightType | MIFARE Ultralight tag type obtained. For details, see [MifareUltralightType](js-apis-nfcTag.md#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();
+// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'mifareUltralight' correctly.
+let getType = mifareClassic.getType();
+console.log("mifareUltralight getType: " + 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**.
@@ -1721,10 +1784,18 @@ Formats this tag as an NDEF tag, and writes an NDEF message to the tag. This API
```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))
- })
+// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'ndef' correctly.
+let data = [0x01, 0x02, ...]; // change it to be correct raw data.
+let ndefmessage = ndef.createNdefMessage(data);
+
+// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'ndefFormatable' correctly.
+ndefFormatable.format(ndefmessage, (err, data)=> {
+ if (err) {
+ console.log("ndefFormatable format err: " + err);
+ } else {
+ console.log("ndefFormatable format data: " + data);
+ }
+});
```
### NdefFormatableTag.format9+
@@ -1741,19 +1812,32 @@ Formats this tag as an NDEF tag, and writes an NDEF message to the tag. This API
| 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.|
+| 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** |
+| ------------------ | --------------------------|
+| callback: AsyncCallback\ | 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))
-})
+// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'ndef' correctly.
+let data = [0x01, 0x02, ...]; // change it to be correct raw data.
+let ndefmessage = ndef.createNdefMessage(data);
+
+// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'ndefFormatable' correctly.
+ndefFormatable.format(ndefmessage, (err, data)=> {
+ if (err) {
+ console.log("ndefFormatable format err: " + err);
+ } else {
+ console.log("ndefFormatable format data: " + data);
+ }
+});
```
### NdefFormatableTag.formatReadOnly9+
@@ -1783,10 +1867,18 @@ Formats this tag as an NDEF tag, writes an NDEF message to the NDEF tag, and the
```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))
- })
+// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'ndef' correctly.
+let data = [0x01, 0x02, ...]; // change it to be correct raw data.
+let ndefmessage = ndef.createNdefMessage(data);
+
+// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'ndefFormatable' correctly.
+ndefFormatable.formatReadOnly(ndefmessage, (err, data)=> {
+ if (err) {
+ console.log("ndefFormatable formatReadOnly err: " + err);
+ } else {
+ console.log("ndefFormatable formatReadOnly data: " + data);
+ }
+});
```
### NdefFormatableTag.formatReadOnly9+
@@ -1803,17 +1895,30 @@ Formats this tag as an NDEF tag, writes an NDEF message to the NDEF tag, and the
| 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.|
+| 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** |
+| ------------------ | --------------------------|
+| callback: AsyncCallback\ | 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))
-})
+// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'ndef' correctly.
+let data = [0x01, 0x02, ...]; // change it to be correct raw data.
+let ndefmessage = ndef.createNdefMessage(data);
+
+// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'ndefFormatable' correctly.
+ndefFormatable.formatReadOnly(ndefmessage, (err, data)=> {
+ if (err) {
+ console.log("ndefFormatable formatReadOnly err: " + err);
+ } else {
+ console.log("ndefFormatable formatReadOnly data: " + data);
+ }
+});
```