提交 687b3a6e 编写于 作者: Z zhangxiuping

Fix the nfc doc for js apis.

Signed-off-by: Nzhangxiuping <zhangxiuping@huawei.com>
上级 5aeee4a2
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:** > ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> 本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 > 本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
## 导入模块 ## 导入模块
``` ```
...@@ -18,7 +17,7 @@ import cardEmulation from '@ohos.nfc.cardEmulation'; ...@@ -18,7 +17,7 @@ import cardEmulation from '@ohos.nfc.cardEmulation';
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
| 名称 | 默认值 | 说明 | | 名称 | 值 | 说明 |
| -------- | -------- | -------- | | -------- | -------- | -------- |
| HCE | 0 | HCE 卡模拟。 | | HCE | 0 | HCE 卡模拟。 |
| UICC | 1 | SIM 卡模拟。 | | UICC | 1 | SIM 卡模拟。 |
...@@ -40,9 +39,9 @@ isSupported(feature: number): boolean ...@@ -40,9 +39,9 @@ isSupported(feature: number): boolean
**返回值:** **返回值:**
| **类型** | **说明** | | **类型** | **说明** |
| -------- | -------- | | -------- | -------- |
| boolean | true: 支持该类型卡模拟,&nbsp;false: 不支持该类型卡模拟。 | | boolean | true: 支持该类型卡模拟,&nbsp;false: 不支持该类型卡模拟。|
## HceService<sup>8+</sup> ## HceService<sup>8+</sup>
......
...@@ -5,14 +5,12 @@ ...@@ -5,14 +5,12 @@
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:** > ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 > 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
## 导入模块 ## 导入模块
``` ```js
import connectedTag from '@ohos.connectedTag'; import connectedTag from '@ohos.connectedTag';
``` ```
## connectedTag.init ## connectedTag.init
init(): boolean init(): boolean
...@@ -23,11 +21,11 @@ init(): boolean ...@@ -23,11 +21,11 @@ init(): boolean
**系统能力**:SystemCapability.Communication.ConnectedTag **系统能力**:SystemCapability.Communication.ConnectedTag
- 返回值: **返回值:**
| **类型** | **说明** |
| -------- | -------- |
| boolean | true:初始化成功,&nbsp;false:初始化失败。 |
| **类型** | **说明** |
| -------- | -------- |
| boolean | true:初始化成功,&nbsp;false:初始化失败。 |
## connectedTag.uninit ## connectedTag.uninit
...@@ -39,11 +37,11 @@ uninit(): boolean ...@@ -39,11 +37,11 @@ uninit(): boolean
**系统能力**:SystemCapability.Communication.ConnectedTag **系统能力**:SystemCapability.Communication.ConnectedTag
- 返回值: **返回值:**
| **类型** | **说明** |
| -------- | -------- |
| boolean | true:卸载操作成功,&nbsp;false:卸载操作失败。 |
| **类型** | **说明** |
| -------- | -------- |
| boolean | true:卸载操作成功,&nbsp;false:卸载操作失败。 |
## connectedTag.readNdefTag ## connectedTag.readNdefTag
...@@ -55,19 +53,21 @@ readNdefTag(): Promise&lt;string&gt; ...@@ -55,19 +53,21 @@ readNdefTag(): Promise&lt;string&gt;
**系统能力**:SystemCapability.Communication.ConnectedTag **系统能力**:SystemCapability.Communication.ConnectedTag
- 返回值: **返回值:**
| **类型** | **说明** |
| -------- | -------- | | **类型** | **说明** |
| Promise&lt;string&gt; | 返回读取有源标签内容。 | | -------- | -------- |
| Promise&lt;string&gt; | 返回读取有源标签内容。 |
**示例:**
- 示例 ```js
``` import connectedTag from '@ohos.connectedTag';
import connectedTag from '@ohos.connectedTag';
connectedTag.readNdefTag().then(result => { connectedTag.readNdefTag().then(result => {
console.log("promise recv ndef response: " + result); console.log("promise recv ndef response: " + result);
}); });
``` ```
## connectedTag.readNdefTag ## connectedTag.readNdefTag
...@@ -79,19 +79,21 @@ readNdefTag(callback: AsyncCallback&lt;string&gt;): void ...@@ -79,19 +79,21 @@ readNdefTag(callback: AsyncCallback&lt;string&gt;): void
**系统能力**:SystemCapability.Communication.ConnectedTag **系统能力**:SystemCapability.Communication.ConnectedTag
- 参数 **参数:**
| **参数名** | **类型** | **必填** | **说明** |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;string&gt; | 是 | 读取有源标签内容回调函数。 |
- 示例 | **参数名** | **类型** | **必填** | **说明** |
``` | -------- | -------- | -------- | -------- |
import connectedTag from '@ohos.connectedTag'; | callback | AsyncCallback&lt;string&gt; | 是 | 读取有源标签内容回调函数。 |
connectedTag.readNdefTag(result => { **示例:**
console.log("callback recv ndef response: " + result);
}); ```js
``` import connectedTag from '@ohos.connectedTag';
connectedTag.readNdefTag(result => {
console.log("callback recv ndef response: " + result);
});
```
## connectedTag.writeNdefTag ## connectedTag.writeNdefTag
...@@ -103,29 +105,32 @@ writeNdefTag(data: string): Promise&lt;void&gt; ...@@ -103,29 +105,32 @@ writeNdefTag(data: string): Promise&lt;void&gt;
**系统能力**:SystemCapability.Communication.ConnectedTag **系统能力**:SystemCapability.Communication.ConnectedTag
- 参数 **参数:**
| **参数名** | **类型** | **必填** | **说明** |
| -------- | -------- | -------- | -------- |
| data | string | 是 | 有源标签内容, 长度最大是1024个字节。 |
- 返回值: | **参数名** | **类型** | **必填** | **说明** |
| **类型** | **说明** | | -------- | -------- | -------- | -------- |
| -------- | -------- | | data | string | 是 | 有源标签内容, 长度最大是1024个字节。 |
| Promise&lt;void&gt; | 无返回值。 |
- 示例 **返回值:**
```
import connectedTag from '@ohos.connectedTag'; | **类型** | **说明** |
| -------- | -------- |
writeNdefTag.write("010203") | Promise&lt;void&gt; | 无返回值。 |
.then((value) => {
// 事件写入正常 **示例:**
console.log(`success to write event: ${value}`);
}).catch((err) => { ```js
// 事件写入异常 import connectedTag from '@ohos.connectedTag';
console.error(`failed to write event because ${err.code}`);
}); connectedTag.write("010203")
``` .then((value) => {
// 事件写入正常
console.log(`success to write event: ${value}`);
}).catch((err) => {
// 事件写入异常
console.error(`failed to write event because ${err.code}`);
});
```
## connectedTag.writeNdefTag ## connectedTag.writeNdefTag
...@@ -137,27 +142,29 @@ writeNdefTag(data: string, callback: AsyncCallback&lt;void&gt;): void ...@@ -137,27 +142,29 @@ writeNdefTag(data: string, callback: AsyncCallback&lt;void&gt;): void
**系统能力**:SystemCapability.Communication.ConnectedTag **系统能力**:SystemCapability.Communication.ConnectedTag
- 参数 **参数:**
| **参数名** | **类型** | **必填** | **说明** |
| -------- | -------- | -------- | -------- |
| data | string | 是 | 有源标签内容, 长度最大是1024个字节。 |
| callback | AsyncCallback&lt;string&gt; | 是 | 读取有源标签内容回调函数。 |
- 示例 | **参数名** | **类型** | **必填** | **说明** |
``` | -------- | -------- | -------- | -------- |
import connectedTag from '@ohos.connectedTag'; | data | string | 是 | 有源标签内容, 长度最大是1024个字节。 |
| callback | AsyncCallback&lt;string&gt; | 是 | 读取有源标签内容回调函数。 |
connectedTag.writeNdefTag("010203", (err, value) => {
if (err) { **示例:**
// 事件写入异常
console.error(`failed to write event because ${err.code}`); ```js
return; import connectedTag from '@ohos.connectedTag';
}
connectedTag.writeNdefTag("010203", (err, value) => {
// 事件写入正常 if (err) {
console.log(`success to write event: ${value}`); // 事件写入异常
}); console.error(`failed to write event because ${err.code}`);
``` return;
}
// 事件写入正常
console.log(`success to write event: ${value}`);
});
```
## connectedTag.on('notify') ## connectedTag.on('notify')
...@@ -169,18 +176,12 @@ on(type: "notify", callback: Callback&lt;number&gt;): void ...@@ -169,18 +176,12 @@ on(type: "notify", callback: Callback&lt;number&gt;): void
**系统能力**:SystemCapability.Communication.ConnectedTag **系统能力**:SystemCapability.Communication.ConnectedTag
- 参数 **参数:**
| **参数名** | **类型** | **必填** | **说明** |
| -------- | -------- | -------- | -------- |
| type | string | 是 | 固定填"notify"字符串 |
| callback | Callback&lt;number&gt; | 是 | 状态改变回调函数。 |
- 状态改变事件的枚举。
| **枚举值** | **说明** |
| -------- | -------- |
| 0 | NFC离场事件 |
| 1 | NFC进场事件 |
| **参数名** | **类型** | **必填** | **说明** |
| -------- | -------- | -------- | -------- |
| type | string | 是 | 固定填"notify"字符串 |
| callback | Callback&lt;number&gt; | 是 | 状态改变回调函数,返回值参见[NfcRfType](#nfcrftype)。 |
## connectedTag.off('notify') ## connectedTag.off('notify')
...@@ -192,28 +193,28 @@ off(type: "notify", callback?: Callback&lt;number&gt;): void ...@@ -192,28 +193,28 @@ off(type: "notify", callback?: Callback&lt;number&gt;): void
**系统能力**:SystemCapability.Communication.ConnectedTag **系统能力**:SystemCapability.Communication.ConnectedTag
- 参数 **参数:**
| **参数名** | **类型** | **必填** | **说明** |
| -------- | -------- | -------- | -------- |
| type | string | 是 | 固定填"notify"字符串 |
| callback | Callback&lt;number&gt; | 否 | 状态改变回调函数。如果callback不填,将“去注册”该事件关联的所有回调函数。 |
- 示例 | **参数名** | **类型** | **必填** | **说明** |
``` | -------- | -------- | -------- | -------- |
import connectedTag from '@ohos.connectedTag'; | type | string | 是 | 固定填"notify"字符串 |
| callback | Callback&lt;number&gt; | 否 | 状态改变回调函数。如果callback不填,将“去注册”该事件关联的所有回调函数。|
var NFC_RF_NOTIFY = "notify";
**示例:**
var recvNfcRfNotifyFunc = result => {
console.info("nfc rf receive state: " + result); ```js
} import connectedTag from '@ohos.connectedTag';
// Register event var recvNfcRfNotifyFunc = result => {
connectedTag.on(NFC_RF_NOTIFY, recvNfcRfNotifyFunc); console.info("nfc rf receive state: " + result);
}
// Unregister event // Register event
connectedTag.off(NFC_RF_NOTIFY, recvNfcRfNotifyFunc); connectedTag.on("notify", recvNfcRfNotifyFunc);
```
// Unregister event
connectedTag.off("notify", recvNfcRfNotifyFunc);
```
## NfcRfType ## NfcRfType
...@@ -221,7 +222,7 @@ off(type: "notify", callback?: Callback&lt;number&gt;): void ...@@ -221,7 +222,7 @@ off(type: "notify", callback?: Callback&lt;number&gt;): void
**系统能力**:SystemCapability.Communication.ConnectedTag **系统能力**:SystemCapability.Communication.ConnectedTag
| 名称 | 默认值 | 说明 | | 名称 | 值 | 说明 |
| -------- | -------- | -------- | | -------- | -------- | -------- |
| NFC_RF_LEAVE | 0 | NFC离场事件 | | NFC_RF_LEAVE | 0 | NFC离场事件 |
| NFC_RF_ENTER | 1 | NFC进场事件 | | NFC_RF_ENTER | 1 | NFC进场事件 |
...@@ -5,10 +5,9 @@ ...@@ -5,10 +5,9 @@
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:** > ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 > 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
## **导入模块** ## **导入模块**
``` ```js
import controller from '@ohos.nfc.controller'; import controller from '@ohos.nfc.controller';
``` ```
...@@ -18,7 +17,7 @@ import controller from '@ohos.nfc.controller'; ...@@ -18,7 +17,7 @@ import controller from '@ohos.nfc.controller';
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
| 名称 | 默认值 | 说明 | | 名称 | 值 | 说明 |
| -------- | -------- | -------- | | -------- | -------- | -------- |
| STATE_OFF | 1 | NFC已关闭状态。 | | STATE_OFF | 1 | NFC已关闭状态。 |
| STATE_TURNING_ON | 2 | NFC正在打开状态。 | | STATE_TURNING_ON | 2 | NFC正在打开状态。 |
...@@ -110,12 +109,10 @@ on(type: "nfcStateChange", callback: Callback&lt;[NfcState](#nfcstate)&gt;): voi ...@@ -110,12 +109,10 @@ on(type: "nfcStateChange", callback: Callback&lt;[NfcState](#nfcstate)&gt;): voi
**参数** **参数**
| **参数名** | **类型** | **必填** | **说明** | | **参数名** | **类型** | **必填** | **说明** |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | 是 | 固定填"nfcStateChange"字符串。 | | type | string | 是 | 固定填"nfcStateChange"字符串。 |
| callback | Callback&lt;[NfcState](#nfcstate)&gt; | 是 | NFC状态改变通知的回调函数。 | | callback | Callback&lt;[NfcState](#nfcstate)&gt; | 是 | NFC状态改变通知的回调函数。 |
## controller.off('nfcStateChange') ## controller.off('nfcStateChange')
...@@ -126,41 +123,38 @@ off(type: "nfcStateChange", callback?: Callback&lt;[NfcState](#nfcstate)&gt;): v ...@@ -126,41 +123,38 @@ off(type: "nfcStateChange", callback?: Callback&lt;[NfcState](#nfcstate)&gt;): v
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
**参数** **参数**
| **参数名** | **类型** | **必填** | **说明** | | **参数名** | **类型** | **必填** | **说明** |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | 是 | 固定填"nfcStateChange"字符串。 | | type | string | 是 | 固定填"nfcStateChange"字符串。 |
| callback | Callback&lt;[NfcState](#nfcstate)&gt; | 否 | NFC状态改变回调函数,可以空缺不填。 | | callback | Callback&lt;[NfcState](#nfcstate)&gt; | 否 | NFC状态改变回调函数,可以空缺不填。 |
**示例** **示例**
```js ```js
import controller from '@ohos.nfc.controller'; import controller from '@ohos.nfc.controller';
// callback key definition
var NFC_STATE_CALLBACK_KEY = "nfcStateChange";
// register callback to receive the nfc state changed notification
controller.on(NFC_STATE_CALLBACK_KEY, (err, nfcState)=> {
if (err) {
console.log("controller on callback err: " + err);
} else {
console.log("controller on callback nfcState: " + nfcState);
}
});
// open nfc, require permission: ohos.permission.MANAGE_SECURE_SETTINGS
if (!controller.isNfcOpen()) {
var ret = controller.openNfc();
console.log("controller openNfc ret: " + ret);
}
// close nfc, require permission: ohos.permission.MANAGE_SECURE_SETTINGS // register callback to receive the nfc state changed notification
if (controller.isNfcOpen()) { controller.on("nfcStateChange", (err, nfcState)=> {
var ret = controller.closeNfc(); if (err) {
console.log("controller closeNfc ret: " + ret); console.log("controller on callback err: " + err);
} else {
console.log("controller on callback nfcState: " + nfcState);
} }
});
// unregister callback
controller.off(NFC_STATE_CALLBACK_KEY); // open nfc, require permission: ohos.permission.MANAGE_SECURE_SETTINGS
``` if (!controller.isNfcOpen()) {
var ret = controller.openNfc();
console.log("controller openNfc ret: " + ret);
}
// close nfc, require permission: ohos.permission.MANAGE_SECURE_SETTINGS
if (controller.isNfcOpen()) {
var ret = controller.closeNfc();
console.log("controller closeNfc ret: " + ret);
}
// unregister callback
controller.off("nfcStateChange");
```
...@@ -59,6 +59,7 @@ import tag from '@ohos.nfc.tag'; ...@@ -59,6 +59,7 @@ import tag from '@ohos.nfc.tag';
``` ```
## **tag.TagInfo** ## **tag.TagInfo**
在对相关Tag类型卡片进行读写之前,必须先获取TagInfo相关属性值,以确认设备读取到的Tag卡片支持哪些技术类型。这样Tag应用程序才能调用正确的接口和所读取到的Tag卡片进行通信。 在对相关Tag类型卡片进行读写之前,必须先获取TagInfo相关属性值,以确认设备读取到的Tag卡片支持哪些技术类型。这样Tag应用程序才能调用正确的接口和所读取到的Tag卡片进行通信。
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
...@@ -69,7 +70,7 @@ onCreate(want, launchParam) { ...@@ -69,7 +70,7 @@ onCreate(want, launchParam) {
// want is initialized by nfc service, contains tag info for this found tag // want is initialized by nfc service, contains tag info for this found tag
var tagInfo; var tagInfo;
try { try {
tag.getTagInfo(want); tagInfo = tag.getTagInfo(want);
} catch (error) { } catch (error) {
console.log("tag.getTagInfo catched error: " + error); console.log("tag.getTagInfo catched error: " + error);
} }
...@@ -191,16 +192,19 @@ getIsoDep(tagInfo: [TagInfo](#taginfo)): [IsoDepTag](js-apis-nfctech.md#isoDepTa ...@@ -191,16 +192,19 @@ getIsoDep(tagInfo: [TagInfo](#taginfo)): [IsoDepTag](js-apis-nfctech.md#isoDepTa
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| --------- | ------------------------- | ---- | ---------------------------------------- | | --------- | ------------------------- | ---- | ---------------------------------------- |
| taginfo | [TagInfo](#taginfo) | 是 | 包含Tag技术类型和相关参数,从tag.getTagInfo(want: Want)获取。 | | taginfo | [TagInfo](#taginfo) | 是 | 包含Tag技术类型和相关参数,从tag.getTagInfo(want: Want)获取。 |
**返回值:** **返回值:**
| **类型** | **说明** | | **类型** | **说明** |
| ---------- | ------------------| | ---------- | ------------------|
| [IsoDepTag](js-apis-nfctech.md#isodeptag9) | IsoDep类型Tag对象,通过该对象访问IsoDep类型的相关接口。 | | [IsoDepTag](js-apis-nfctech.md#isodeptag9) | IsoDep类型Tag对象,通过该对象访问IsoDep类型的相关接口。 |
**错误码:** **错误码:**
以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md) 以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md)
| 错误码ID | 错误信息| | 错误码ID | 错误信息|
| ------- | -------| | ------- | -------|
...@@ -215,16 +219,19 @@ getNdef(tagInfo: [TagInfo](#taginfo)): [NdefTag](js-apis-nfctech.md#ndeftag9) ...@@ -215,16 +219,19 @@ getNdef(tagInfo: [TagInfo](#taginfo)): [NdefTag](js-apis-nfctech.md#ndeftag9)
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| --------- | ------------------------- | ---- | ---------------------------------------- | | --------- | ------------------------- | ---- | ---------------------------------------- |
| taginfo | [TagInfo](#taginfo) | 是 | 包含Tag技术类型和相关参数,从tag.getTagInfo(want: Want)获取。 | | taginfo | [TagInfo](#taginfo) | 是 | 包含Tag技术类型和相关参数,从tag.getTagInfo(want: Want)获取。 |
**返回值:** **返回值:**
| **类型** | **说明** | | **类型** | **说明** |
| ---------| -------------- | | ---------| -------------- |
| [NdefTag](js-apis-nfctech.md#ndeftag9) | NDEF类型Tag对象,通过该对象访问NDEF类型的相关接口。| | [NdefTag](js-apis-nfctech.md#ndeftag9) | NDEF类型Tag对象,通过该对象访问NDEF类型的相关接口。|
**错误码:** **错误码:**
以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md) 以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md)
| 错误码ID | 错误信息| | 错误码ID | 错误信息|
| ------- | -------| | ------- | -------|
...@@ -239,11 +246,13 @@ getMifareClassic(tagInfo: [TagInfo](#taginfo)): [MifareClassicTag](js-apis-nfcte ...@@ -239,11 +246,13 @@ getMifareClassic(tagInfo: [TagInfo](#taginfo)): [MifareClassicTag](js-apis-nfcte
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| --------- | ------------------------- | ---- | ---------------------------------------- | | --------- | ------------------------- | ---- | ---------------------------------------- |
| taginfo | [TagInfo](#taginfo) | 是 | 包含Tag技术类型和相关参数,从tag.getTagInfo(want: Want)获取。 | | taginfo | [TagInfo](#taginfo) | 是 | 包含Tag技术类型和相关参数,从tag.getTagInfo(want: Want)获取。 |
**返回值:** **返回值:**
| **类型** | **说明** | | **类型** | **说明** |
| ----------------- | ------------------------| | ----------------- | ------------------------|
| [MifareClassicTag](js-apis-nfctech.md#mifareclassictag-9) | MIFARE Classic类型Tag对象,通过该对象访问MIFARE Classic类型的相关接口。 | | [MifareClassicTag](js-apis-nfctech.md#mifareclassictag-9) | MIFARE Classic类型Tag对象,通过该对象访问MIFARE Classic类型的相关接口。 |
...@@ -268,11 +277,13 @@ getMifareUltralight(tagInfo: [TagInfo](#taginfo)): [MifareUltralightTag](js-apis ...@@ -268,11 +277,13 @@ getMifareUltralight(tagInfo: [TagInfo](#taginfo)): [MifareUltralightTag](js-apis
| taginfo | [TagInfo](#taginfo) | 是 | 包含Tag技术类型和相关参数,从tag.getTagInfo(want: Want)获取。 | | taginfo | [TagInfo](#taginfo) | 是 | 包含Tag技术类型和相关参数,从tag.getTagInfo(want: Want)获取。 |
**返回值:** **返回值:**
| **类型** | **说明** | | **类型** | **说明** |
| -------------------- | ---------------------------| | -------------------- | ---------------------------|
| [MifareUltralightTag](js-apis-nfctech.md#mifareultralighttag9) | MIFARE Ultralight类型Tag对象,通过该对象访问MIFARE Ultralight类型的相关接口。 | | [MifareUltralightTag](js-apis-nfctech.md#mifareultralighttag9) | MIFARE Ultralight类型Tag对象,通过该对象访问MIFARE Ultralight类型的相关接口。 |
**错误码:** **错误码:**
以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md) 以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md)
| 错误码ID | 错误信息| | 错误码ID | 错误信息|
| ------- | -------| | ------- | -------|
...@@ -287,11 +298,13 @@ getNdefFormatable(tagInfo: [TagInfo](#taginfo)): [NdefFormatableTag](js-apis-nfc ...@@ -287,11 +298,13 @@ getNdefFormatable(tagInfo: [TagInfo](#taginfo)): [NdefFormatableTag](js-apis-nfc
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
**返回值:** **返回值:**
| **类型** | **说明** | | **类型** | **说明** |
| ------------------ | --------------------------| | ------------------ | --------------------------|
| [NdefFormatableTag](js-apis-nfctech.md#ndefformatabletag) | NDEF Formatable类型Tag对象,通过该对象访问NDEF Formatable类型的相关接口。 | | [NdefFormatableTag](js-apis-nfctech.md#ndefformatabletag) | NDEF Formatable类型Tag对象,通过该对象访问NDEF Formatable类型的相关接口。 |
**错误码:** **错误码:**
以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md) 以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md)
| 错误码ID | 错误信息| | 错误码ID | 错误信息|
| ------- | -------| | ------- | -------|
...@@ -306,11 +319,13 @@ getTagInfo(want: [Want](js-apis-application-Want.md#Want)): [TagInfo](#taginfo) ...@@ -306,11 +319,13 @@ getTagInfo(want: [Want](js-apis-application-Want.md#Want)): [TagInfo](#taginfo)
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| --------- | ------------------------- | ---- | ---------------------------------------- | | --------- | ------------------------- | ---- | ---------------------------------------- |
| want | [Want](js-apis-application-Want.md#Want) | 是 | 分发Ability时,在系统onCreate入口函数的参数中获取。 | | want | [Want](js-apis-application-Want.md#Want) | 是 | 分发Ability时,在系统onCreate入口函数的参数中获取。 |
**返回值:** **返回值:**
| **类型** | **说明** | | **类型** | **说明** |
| ------------------ | --------------------------| | ------------------ | --------------------------|
| [TagInfo](#taginfo) | TagInfo对象,用于获取不同技术类型的Tag对象。 | | [TagInfo](#taginfo) | TagInfo对象,用于获取不同技术类型的Tag对象。 |
...@@ -331,11 +346,13 @@ makeUriRecord(uri: string): [NdefRecord](#ndefrecord9); ...@@ -331,11 +346,13 @@ makeUriRecord(uri: string): [NdefRecord](#ndefrecord9);
| uri | string | 是 | 写入到NDEF Record里面的数据内容。 | | uri | string | 是 | 写入到NDEF Record里面的数据内容。 |
**返回值:** **返回值:**
| **类型** | **说明** | | **类型** | **说明** |
| ------------------ | --------------------------| | ------------------ | --------------------------|
| [NdefRecord](#ndefrecord9) | NDEF标签的Record,详见NDEF技术规范《NFCForum-TS-NDEF_1.0》。 | | [NdefRecord](#ndefrecord9) | NDEF标签的Record,详见NDEF技术规范《NFCForum-TS-NDEF_1.0》。 |
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
...@@ -362,17 +379,20 @@ makeTextRecord(text: string, locale: string): [NdefRecord](#ndefrecord9); ...@@ -362,17 +379,20 @@ makeTextRecord(text: string, locale: string): [NdefRecord](#ndefrecord9);
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | -------------------------------------- | | -------- | ----------------------- | ---- | -------------------------------------- |
| text | string | 是 | 写入到NDEF Record里面的文本数据内容。 | | text | string | 是 | 写入到NDEF Record里面的文本数据内容。 |
| locale | string | 是 | 文本数据内容的编码方式。 | | locale | string | 是 | 文本数据内容的编码方式。 |
**返回值:** **返回值:**
| **类型** | **说明** | | **类型** | **说明** |
| ------------------ | --------------------------| | ------------------ | --------------------------|
| [NdefRecord](#ndefrecord9) | NDEF标签的Record,详见NDEF技术规范《NFCForum-TS-NDEF_1.0》。 | | [NdefRecord](#ndefrecord9) | NDEF标签的Record,详见NDEF技术规范《NFCForum-TS-NDEF_1.0》。 |
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
...@@ -398,26 +418,29 @@ makeMimeRecord(mimeType: string, mimeData: number[]): [NdefRecord](#ndefrecord9) ...@@ -398,26 +418,29 @@ makeMimeRecord(mimeType: string, mimeData: number[]): [NdefRecord](#ndefrecord9)
根据输入的MIME数据和类型,构建NDEF标签的Record。 根据输入的MIME数据和类型,构建NDEF标签的Record。
**系统能力**:SystemCapability.Communication.NFC **系统能力**:SystemCapability.Communication.NFC.Core
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | -------------------------------------- | | -------- | ----------------------- | ---- | -------------------------------------- |
| mimeType | string | 是 | 符合RFC规则的MIME类型,比如"text/plain"或"image/jpeg"。 | | mimeType | string | 是 | 符合RFC规则的MIME类型,比如"text/plain"或"image/jpeg"。 |
| mimeData | number[] | 是 | MIME数据内容,每个number十六进制表示,范围是0x00~0xFF。 | | mimeData | number[] | 是 | MIME数据内容,每个number十六进制表示,范围是0x00~0xFF。 |
**返回值:** **返回值:**
| **类型** | **说明** | | **类型** | **说明** |
| ------------------ | --------------------------| | ------------------ | --------------------------|
| [NdefRecord](#ndefrecord9) | NDEF标签的Record,详见NDEF技术规范《NFCForum-TS-NDEF_1.0》。 | | [NdefRecord](#ndefrecord9) | NDEF标签的Record,详见NDEF技术规范《NFCForum-TS-NDEF_1.0》。 |
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
try { try {
let mimeType = "text/plain"; // change it to be correct. let mimeType = "text/plain"; // change it to be correct.
let mimeData = [0x01, 0x02, 0x03, 0x04, ...]; // change it to be correct. let mimeData = [0x01, 0x02, 0x03, 0x04]; // change it to be correct.
let ndefRecord = tag.ndef.makeMimeRecord(mimeType, mimeData); let ndefRecord = tag.ndef.makeMimeRecord(mimeType, mimeData);
if (ndefRecord != undefined) { if (ndefRecord != undefined) {
console.log("ndefMessage makeMimeRecord rtdType: " + ndefRecord.rtdType); console.log("ndefMessage makeMimeRecord rtdType: " + ndefRecord.rtdType);
...@@ -435,9 +458,10 @@ makeExternalRecord(domainName: string, type: string, externalData: number[]): [N ...@@ -435,9 +458,10 @@ makeExternalRecord(domainName: string, type: string, externalData: number[]): [N
根据应用程序特定的外部数据,构建NDEF标签的Record。 根据应用程序特定的外部数据,构建NDEF标签的Record。
**系统能力**:SystemCapability.Communication.NFC **系统能力**:SystemCapability.Communication.NFC.Core
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | -------------------------------------- | | -------- | ----------------------- | ---- | -------------------------------------- |
| domainName | string | 是 | 外部数据发布组织的域名,一般是应用程序的包名。 | | domainName | string | 是 | 外部数据发布组织的域名,一般是应用程序的包名。 |
...@@ -445,18 +469,20 @@ makeExternalRecord(domainName: string, type: string, externalData: number[]): [N ...@@ -445,18 +469,20 @@ makeExternalRecord(domainName: string, type: string, externalData: number[]): [N
| externalData | number[] | 是 | 外部数据内容,每个number十六进制表示,范围是0x00~0xFF。 | | externalData | number[] | 是 | 外部数据内容,每个number十六进制表示,范围是0x00~0xFF。 |
**返回值:** **返回值:**
| **类型** | **说明** | | **类型** | **说明** |
| ------------------ | --------------------------| | ------------------ | --------------------------|
| [NdefRecord](#ndefrecord9) | NDEF标签的Record,详见NDEF技术规范《NFCForum-TS-NDEF_1.0》。 | | [NdefRecord](#ndefrecord9) | NDEF标签的Record,详见NDEF技术规范《NFCForum-TS-NDEF_1.0》。 |
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
try { try {
let domainName = "ohos.nfc.application"; // change it to be correct. let domainName = "ohos.nfc.application"; // change it to be correct.
let type = "test"; // change it to be correct. let type = "test"; // change it to be correct.
let externalData = [0x01, 0x02, 0x03, 0x04, ...]; // change it to be correct. let externalData = [0x01, 0x02, 0x03, 0x04]; // change it to be correct.
let ndefRecord = tag.ndef.makeExternalRecord(domainName, type, externalData); let ndefRecord = tag.ndef.makeExternalRecord(domainName, type, externalData);
if (ndefRecord != undefined) { if (ndefRecord != undefined) {
console.log("ndefMessage makeExternalRecord rtdType: " + ndefRecord.rtdType); console.log("ndefMessage makeExternalRecord rtdType: " + ndefRecord.rtdType);
...@@ -475,19 +501,22 @@ messageToBytes(ndefMessage: [NdefMessage](js-apis-nfctech.md#ndefmessage9)): num ...@@ -475,19 +501,22 @@ messageToBytes(ndefMessage: [NdefMessage](js-apis-nfctech.md#ndefmessage9)): num
把输入的NDEF消息数据对象,转换为字节格式的数据。 把输入的NDEF消息数据对象,转换为字节格式的数据。
**系统能力**:SystemCapability.Communication.NFC **系统能力**:SystemCapability.Communication.NFC.Core
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | -------------------------------------- | | -------- | ----------------------- | ---- | -------------------------------------- |
| ndefMessage | [NdefMessage](js-apis-nfctech.md#ndefmessage9) | 是 | NDEF消息数据对象。 | | ndefMessage | [NdefMessage](js-apis-nfctech.md#ndefmessage9) | 是 | NDEF消息数据对象。 |
**返回值:** **返回值:**
| **类型** | **说明** | | **类型** | **说明** |
| ------------------ | --------------------------| | ------------------ | --------------------------|
| number[] | NDEF消息数据对象,所转换成的字节格式的数据。每个number十六进制表示,范围是0x00~0xFF。 | | number[] | NDEF消息数据对象,所转换成的字节格式的数据。每个number十六进制表示,范围是0x00~0xFF。 |
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
...@@ -513,14 +542,16 @@ createNdefMessage(data: number[]): [NdefMessage](js-apis-nfctech.md#ndefmessage9 ...@@ -513,14 +542,16 @@ createNdefMessage(data: number[]): [NdefMessage](js-apis-nfctech.md#ndefmessage9
使用原始字节数据创建NDEF标签的Message。该数据必须符合NDEF Record数据格式,如果不符合格式,则返回的NdeMessage数据对象,所包含的NDE Record列表会为空。 使用原始字节数据创建NDEF标签的Message。该数据必须符合NDEF Record数据格式,如果不符合格式,则返回的NdeMessage数据对象,所包含的NDE Record列表会为空。
**系统能力**:SystemCapability.Communication.NFC **系统能力**:SystemCapability.Communication.NFC.Core
**参数:** **参数:**
| **参数名** | **类型** | **必填** | **说明** | | **参数名** | **类型** | **必填** | **说明** |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| data | number[] | 是 | 原始字节,每个number十六进制表示,范围是0x00~0xFF。要求必须满足NDEF Record的格式。 | | data | number[] | 是 | 原始字节,每个number十六进制表示,范围是0x00~0xFF。要求必须满足NDEF Record的格式。 |
**返回值:** **返回值:**
| **类型** | **说明** | | **类型** | **说明** |
| ------------------ | --------------------------| | ------------------ | --------------------------|
| [NdefMessage](js-apis-nfctech.md#ndefmessage9) | NDEF标签的Message,详见NDEF技术规范《NFCForum-TS-NDEF_1.0》。 | | [NdefMessage](js-apis-nfctech.md#ndefmessage9) | NDEF标签的Message,详见NDEF技术规范《NFCForum-TS-NDEF_1.0》。 |
...@@ -548,16 +579,19 @@ createNdefMessage(ndefRecords: NdefRecord[]): [NdefMessage](js-apis-nfctech.md#n ...@@ -548,16 +579,19 @@ createNdefMessage(ndefRecords: NdefRecord[]): [NdefMessage](js-apis-nfctech.md#n
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
**参数:** **参数:**
| **参数名** | **类型** | **必填** | **说明** | | **参数名** | **类型** | **必填** | **说明** |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| ndefRecords | [NdefRecord](js-apis-nfcTag.md#ndefrecord9)[] | 是 | NDEF标签的Record列表,详见NDEF技术规范《NFCForum-TS-NDEF_1.0》。 | | ndefRecords | [NdefRecord](js-apis-nfcTag.md#ndefrecord9)[] | 是 | NDEF标签的Record列表,详见NDEF技术规范《NFCForum-TS-NDEF_1.0》。 |
**返回值:** **返回值:**
| **类型** | **说明** | | **类型** | **说明** |
| ------------------ | --------------------------| | ------------------ | --------------------------|
| [NdefMessage](js-apis-nfctech.md#ndefmessage9) | NDEF标签的Message,详见NDEF技术规范《NFCForum-TS-NDEF_1.0》。| | [NdefMessage](js-apis-nfctech.md#ndefmessage9) | NDEF标签的Message,详见NDEF技术规范《NFCForum-TS-NDEF_1.0》。|
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
...@@ -581,30 +615,30 @@ NFC服务在读取到标签时给出的对象,通过改对象属性,应用 ...@@ -581,30 +615,30 @@ NFC服务在读取到标签时给出的对象,通过改对象属性,应用
**需要权限**:ohos.permission.NFC_TAG **需要权限**:ohos.permission.NFC_TAG
| **参数名** | **类型** | **说明** | | **名称** | **类型** | **可读** | **可写** | **说明** |
| -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| uid<sup>9+</sup> | number[] | 标签的uid,每个number值是十六进制表示,范围是0x00~0xFF。 | | uid<sup>9+</sup> | number[] | 是 | 否 | 标签的uid,每个number值是十六进制表示,范围是0x00~0xFF。 |
| technology<sup>9+</sup> | number[] | 支持的技术类型,每个number值表示所支持技术类型的常量值。 | | technology<sup>9+</sup> | number[] | 是 | 否 | 支持的技术类型,每个number值表示所支持技术类型的常量值。 |
| supportedProfiles | number[] | 支持的技术类型,从API9开始不支持,使用technology替代。 | | supportedProfiles | number[] | 是 | 否 | 支持的技术类型,从API9开始不支持,使用technology替代。 |
## NdefRecord<sup>9+</sup> ## NdefRecord<sup>9+</sup>
NDEF标签Record属性的定义,参考NDEF标签技术规范《NFCForum-TS-NDEF_1.0》的定义细节。 NDEF标签Record属性的定义,参考NDEF标签技术规范《NFCForum-TS-NDEF_1.0》的定义细节。
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
| **参数名** | **类型** | **说明** | | **名称** | **类型** | **可读** | **可写** | **说明** |
| -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| tnf | number | NDEF Record的TNF(Type Name Field)。 | | tnf | number | 是 | 否 | NDEF Record的TNF(Type Name Field)。 |
| rtdType| number[] | NDEF Record的RTD(Record Type Definition)类型值,每个number十六进制表示,范围是0x00~0xFF。 | | rtdType| number[] | 是 | 否 | NDEF Record的RTD(Record Type Definition)类型值,每个number十六进制表示,范围是0x00~0xFF。 |
| id | number[] | NDEF Record的ID,每个number十六进制表示,范围是0x00~0xFF。| | id | number[] | 是 | 否 | NDEF Record的ID,每个number十六进制表示,范围是0x00~0xFF。|
| payload | number[] | NDEF Record的PAYLOAD,每个number十六进制表示,范围是0x00~0xFF。 | | payload | number[] | 是 | 否 | NDEF Record的PAYLOAD,每个number十六进制表示,范围是0x00~0xFF。 |
## 技术类型定义 ## 技术类型定义
NFC Tag有多种不同的技术类型,定义常量描述不同的技术类型。 NFC Tag有多种不同的技术类型,定义常量描述不同的技术类型。
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
| **参数名** | **常量值** | **说明** | | **名称** | **值** | **说明** |
| -------- | -------- | -------- | | -------- | -------- | -------- |
| NFC_A | 1 | NFC-A (ISO 14443-3A)技术。| | NFC_A | 1 | NFC-A (ISO 14443-3A)技术。|
| NFC_B | 2 | NFC-A (ISO 14443-3B)技术。| | NFC_B | 2 | NFC-A (ISO 14443-3B)技术。|
...@@ -621,7 +655,7 @@ NDEF Record的TNF(Type Name Field)类型值,参考NDEF标签技术规范《NFC ...@@ -621,7 +655,7 @@ NDEF Record的TNF(Type Name Field)类型值,参考NDEF标签技术规范《NFC
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
| **参数名** | **常量值** | **说明** | | **名称** | **值** | **说明** |
| -------- | -------- | -------- | | -------- | -------- | -------- |
| TNF_EMPTY | 0x0 | Empty。| | TNF_EMPTY | 0x0 | Empty。|
| TNF_WELL_KNOWN | 0x01 | NFC Forum well-known type [NFC RTD]。| | TNF_WELL_KNOWN | 0x01 | NFC Forum well-known type [NFC RTD]。|
...@@ -636,7 +670,7 @@ NDEF Record的RTD(Record Type Definition)类型值,参考NDEF标签技术规 ...@@ -636,7 +670,7 @@ NDEF Record的RTD(Record Type Definition)类型值,参考NDEF标签技术规
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
| **参数名** | **常量值** | **说明** | | **名称** | **值** | **说明** |
| -------- | -------- | -------- | | -------- | -------- | -------- |
| RTD_TEXT<sup>9+</sup> | [0x54] | 文本类型的NDEF Record。| | RTD_TEXT<sup>9+</sup> | [0x54] | 文本类型的NDEF Record。|
| RTD_URI<sup>9+</sup> | [0x55] | URI类型的NDEF Record。| | RTD_URI<sup>9+</sup> | [0x55] | URI类型的NDEF Record。|
...@@ -646,7 +680,7 @@ NFC Forum标准里面Tag类型的定义。 ...@@ -646,7 +680,7 @@ NFC Forum标准里面Tag类型的定义。
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
| **参数名** | **常量值** | **说明** | | **名称** | **值** | **说明** |
| -------- | -------- | -------- | | -------- | -------- | -------- |
| NFC_FORUM_TYPE_1 | 1 | NFC论坛类型1。 | | NFC_FORUM_TYPE_1 | 1 | NFC论坛类型1。 |
| NFC_FORUM_TYPE_2 | 2 | NFC论坛类型2。 | | NFC_FORUM_TYPE_2 | 2 | NFC论坛类型2。 |
...@@ -659,7 +693,7 @@ MIFARE Classic标签类型的定义。 ...@@ -659,7 +693,7 @@ MIFARE Classic标签类型的定义。
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
| **参数名** | **常量值** | **说明** | | **名称** | **值** | **说明** |
| -------- | -------- | -------- | | -------- | -------- | -------- |
| TYPE_UNKNOWN | 0 | 未知的MIFARE类型。 | | TYPE_UNKNOWN | 0 | 未知的MIFARE类型。 |
| TYPE_CLASSIC | 1 | MIFARE Classic类型。| | TYPE_CLASSIC | 1 | MIFARE Classic类型。|
...@@ -671,7 +705,7 @@ MIFARE Classic标签存储大小的定义。 ...@@ -671,7 +705,7 @@ MIFARE Classic标签存储大小的定义。
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
| **参数名** | **常量值** | **说明** | | **名称** | **值** | **说明** |
| -------- | -------- | -------- | | -------- | -------- | -------- |
| MC_SIZE_MINI | 320 | 每个标签5个扇区,每个扇区4个块。 | | MC_SIZE_MINI | 320 | 每个标签5个扇区,每个扇区4个块。 |
| MC_SIZE_1K | 1024 | 每个标签16个扇区,每个扇区4个块。| | MC_SIZE_1K | 1024 | 每个标签16个扇区,每个扇区4个块。|
...@@ -683,9 +717,9 @@ MIFARE Ultralight标签类型的定义。 ...@@ -683,9 +717,9 @@ MIFARE Ultralight标签类型的定义。
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
| **参数名** | **常量值** | **说明** | | **名称** | **值** | **说明** |
| -------- | -------- | -------- | | -------- | -------- | -------- |
| TYPE_UNKOWN | 0 | 未知的 MIFARE 类型。 | | TYPE_UNKNOWN | 0 | 未知的 MIFARE 类型。 |
| TYPE_ULTRALIGHT | 1 | MIFARE Ultralight类型。| | TYPE_ULTRALIGHT | 1 | MIFARE Ultralight类型。|
| TYPE_ULTRALIGHT_C | 2 | MIFARE UltralightC 类型。 | | TYPE_ULTRALIGHT_C | 2 | MIFARE UltralightC 类型。 |
<!--no_check--> <!--no_check-->
\ No newline at end of file
...@@ -13,7 +13,7 @@ import tag from '@ohos.nfc.tag'; ...@@ -13,7 +13,7 @@ import tag from '@ohos.nfc.tag';
## NfcATag ## NfcATag
NfcATag 提供 NFC-A(ISO 14443-3A)技术的属性和I/O操作的访问,继承自TagSession NfcATag 提供 NFC-A(ISO 14443-3A)技术的属性和I/O操作的访问,继承自[TagSession](js-apis-tagSession.md)
TagSession是所有NFC Tag技术类型的基类, 提供建立连接和发送数据等共同接口。具体请参见[TagSession](js-apis-tagSession.md) TagSession是所有NFC Tag技术类型的基类, 提供建立连接和发送数据等共同接口。具体请参见[TagSession](js-apis-tagSession.md)
...@@ -268,11 +268,13 @@ getHistoricalBytes(): number[] ...@@ -268,11 +268,13 @@ getHistoricalBytes(): number[]
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
**返回值:** **返回值:**
| **类型** | **说明** | | **类型** | **说明** |
| ------------------ | --------------------------| | ------------------ | --------------------------|
| number[] | IsoDepTag 标签的历史字节,每个number十六进制表示,范围是0x00~0xFF。如果该IsoDep类型Tag是基于NfcB技术的,则该返回值为空。| | number[] | IsoDepTag 标签的历史字节,每个number十六进制表示,范围是0x00~0xFF。如果该IsoDep类型Tag是基于NfcB技术的,则该返回值为空。|
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
...@@ -290,11 +292,13 @@ getHiLayerResponse(): number[] ...@@ -290,11 +292,13 @@ getHiLayerResponse(): number[]
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
**返回值:** **返回值:**
| **类型** | **说明** | | **类型** | **说明** |
| ------------------ | --------------------------| | ------------------ | --------------------------|
| number[] | IsoDepTag 标签的更高层响应字节,每个number十六进制表示,范围是0x00~0xFF。如果该IsoDep类型Tag是基于NfcA技术的,则该返回值为空。| | number[] | IsoDepTag 标签的更高层响应字节,每个number十六进制表示,范围是0x00~0xFF。如果该IsoDep类型Tag是基于NfcA技术的,则该返回值为空。|
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
...@@ -314,17 +318,20 @@ isExtendedApduSupported(): Promise&lt;boolean&gt; ...@@ -314,17 +318,20 @@ isExtendedApduSupported(): Promise&lt;boolean&gt;
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
**返回值:** **返回值:**
| **类型** | **说明** | | **类型** | **说明** |
| ------------------ | --------------------------| | ------------------ | --------------------------|
| Promise&lt;boolean&gt; | 检查结果,true: 支持, false: 不支持。| | Promise&lt;boolean&gt; | 检查结果,true: 支持, false: 不支持。|
**错误码:** **错误码:**
以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md) 以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md)
| 错误码ID | 错误信息| | 错误码ID | 错误信息|
| ------- | -------| | ------- | -------|
| 3100201 | Tag running state is abnormal in service. | | 3100201 | Tag running state is abnormal in service. |
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
...@@ -361,16 +368,20 @@ isExtendedApduSupported(callback: AsyncCallback\<boolean>): void ...@@ -361,16 +368,20 @@ isExtendedApduSupported(callback: AsyncCallback\<boolean>): void
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | -------------------------------------- | | -------- | ----------------------- | ---- | -------------------------------------- |
| callback | AsyncCallback\<boolean> | 是 | 回调函数,true: 支持, false: 不支持。 | | callback | AsyncCallback\<boolean> | 是 | 回调函数,true: 支持, false: 不支持。 |
**错误码:** **错误码:**
以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md) 以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md)
| 错误码ID | 错误信息| | 错误码ID | 错误信息|
| ------- | -------| | ------- | -------|
| 3100201 | Tag running state is abnormal in service. | | 3100201 | Tag running state is abnormal in service. |
**示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
...@@ -401,18 +412,20 @@ try { ...@@ -401,18 +412,20 @@ try {
### NdefMessage.getNdefRecords<sup>9+</sup> ### NdefMessage.getNdefRecords<sup>9+</sup>
getNdefRecords(): [NdefRecord](js-apis-nfcTag.md#ndefrecord9)[] getNdefRecords(): [tag.NdefRecord](js-apis-nfcTag.md#ndefrecord9)[]
获取NDEF消息中的所有记录。 获取NDEF消息中的所有记录。
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
**返回值:** **返回值:**
| **类型** | **说明** | | **类型** | **说明** |
| ------------------ | --------------------------| | ------------------ | --------------------------|
| [NdefRecord](js-apis-nfcTag.md#ndefrecord9)[] | NDEF标签的Record列表,详见NDEF技术规范《NFCForum-TS-NDEF_1.0》。 | | [tag.NdefRecord](js-apis-nfcTag.md#ndefrecord9)[] | NDEF标签的Record列表,详见NDEF技术规范《NFCForum-TS-NDEF_1.0》。 |
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
...@@ -434,18 +447,20 @@ TagSession是所有NFC Tag技术类型的基类, 提供建立连接和发送 ...@@ -434,18 +447,20 @@ TagSession是所有NFC Tag技术类型的基类, 提供建立连接和发送
### NdefTag.getNdefTagType<sup>9+</sup> ### NdefTag.getNdefTagType<sup>9+</sup>
getNdefTagType(): NfcForumType getNdefTagType(): [tag.NfcForumType](js-apis-nfcTag.md#nfcforumtype9)
获取NDEF标签的类型。 获取NDEF标签的类型。
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
**返回值:** **返回值:**
| **类型** | **说明** | | **类型** | **说明** |
| ------------------ | --------------------------| | ------------------ | --------------------------|
| [NfcForumType](js-apis-nfcTag.md#nfcforumtype9) | NDEF标签类型,包括NFC FORUM TYPE 1/2/3/4等。| | [tag.NfcForumType](js-apis-nfcTag.md#nfcforumtype9) | NDEF标签类型,包括NFC FORUM TYPE 1/2/3/4等。|
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
...@@ -456,13 +471,14 @@ console.log("ndef ndefTagType: " + ndefTagType); ...@@ -456,13 +471,14 @@ console.log("ndef ndefTagType: " + ndefTagType);
### NdefTag.getNdefMessage<sup>9+</sup> ### NdefTag.getNdefMessage<sup>9+</sup>
getNdefMessage(): NdefMessage getNdefMessage(): [NdefMessage](#ndefmessage9)
获取发现NDEF标签时,从标签读取的Message。 获取发现NDEF标签时,从标签读取的Message。
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
**返回值:** **返回值:**
| **类型** | **说明** | | **类型** | **说明** |
| ------------------ | --------------------------| | ------------------ | --------------------------|
| [NdefMessage](#ndefmessage9) | NDEF标签的Message,详见NDEF技术规范《NFCForum-TS-NDEF_1.0》。| | [NdefMessage](#ndefmessage9) | NDEF标签的Message,详见NDEF技术规范《NFCForum-TS-NDEF_1.0》。|
...@@ -485,11 +501,13 @@ isNdefWritable(): boolean; ...@@ -485,11 +501,13 @@ isNdefWritable(): boolean;
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
**返回值:** **返回值:**
| **类型** | **说明** | | **类型** | **说明** |
| ------------------ | --------------------------| | ------------------ | --------------------------|
| boolean | 检查结果,true: 可写, false: 不可写。| | boolean | 检查结果,true: 可写, false: 不可写。|
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
...@@ -500,7 +518,7 @@ console.log("ndef isNdefWritable: " + isWritable); ...@@ -500,7 +518,7 @@ console.log("ndef isNdefWritable: " + isWritable);
### NdefTag.readNdef<sup>9+</sup> ### NdefTag.readNdef<sup>9+</sup>
readNdef(): Promise\<NdefMessage> readNdef(): Promise\<[NdefMessage](#ndefmessage9)>
读取标签上的NDEF消息,使用Promise方式作为异步方法。 读取标签上的NDEF消息,使用Promise方式作为异步方法。
...@@ -509,17 +527,20 @@ readNdef(): Promise\<NdefMessage> ...@@ -509,17 +527,20 @@ readNdef(): Promise\<NdefMessage>
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
**返回值:** **返回值:**
| **类型** | **说明** | | **类型** | **说明** |
| ------------------ | --------------------------| | ------------------ | --------------------------|
| Promise\<[NdefMessage](#ndefmessage9)> | 以Promise形式返回从NDEF标签中读取到的Message数据对象。| | Promise\<[NdefMessage](#ndefmessage9)> | 以Promise形式返回从NDEF标签中读取到的Message数据对象。|
**错误码:** **错误码:**
以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md) 以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md)
| 错误码ID | 错误信息| | 错误码ID | 错误信息|
| ------- | -------| | ------- | -------|
| 3100201 | Tag running state is abnormal in service. | | 3100201 | Tag running state is abnormal in service. |
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
...@@ -555,17 +576,20 @@ readNdef(callback: AsyncCallback\<[NdefMessage](#ndefmessage9)>): void ...@@ -555,17 +576,20 @@ readNdef(callback: AsyncCallback\<[NdefMessage](#ndefmessage9)>): void
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | -------------------------------------- | | -------- | ----------------------- | ---- | -------------------------------------- |
| callback | AsyncCallback\<[NdefMessage](#ndefmessage9)> | 是 | 回调函数,返回从NDEF标签中读取到的Message信息。| | callback | AsyncCallback\<[NdefMessage](#ndefmessage9)> | 是 | 回调函数,返回从NDEF标签中读取到的Message信息。|
**错误码:** **错误码:**
以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md) 以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md)
| 错误码ID | 错误信息| | 错误码ID | 错误信息|
| ------- | -------| | ------- | -------|
| 3100201 | Tag running state is abnormal in service. | | 3100201 | Tag running state is abnormal in service. |
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
...@@ -603,17 +627,20 @@ writeNdef(msg: NdefMessage): Promise\<void>; ...@@ -603,17 +627,20 @@ writeNdef(msg: NdefMessage): Promise\<void>;
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | -------------------------------------- | | -------- | ----------------------- | ---- | -------------------------------------- |
| msg | NdefMessage | 是 | NDEF Message数据对象。| | msg | NdefMessage | 是 | NDEF Message数据对象。|
**错误码:** **错误码:**
以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md) 以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md)
| 错误码ID | 错误信息| | 错误码ID | 错误信息|
| ------- | -------| | ------- | -------|
| 3100201 | Tag running state is abnormal in service. | | 3100201 | Tag running state is abnormal in service. |
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
...@@ -643,7 +670,7 @@ try { ...@@ -643,7 +670,7 @@ try {
### NdefTag.writeNdef<sup>9+</sup> ### NdefTag.writeNdef<sup>9+</sup>
writeNdef(msg: NdefMessage, callback: AsyncCallback\<void>): void writeNdef(msg: [NdefMessage](#ndefmessage9), callback: AsyncCallback\<void>): void
将NDEF Message数据对象写入此标签,使用AsyncCallback方式作为异步方法。 将NDEF Message数据对象写入此标签,使用AsyncCallback方式作为异步方法。
...@@ -652,18 +679,21 @@ writeNdef(msg: NdefMessage, callback: AsyncCallback\<void>): void ...@@ -652,18 +679,21 @@ writeNdef(msg: NdefMessage, callback: AsyncCallback\<void>): void
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | -------------------------------------- | | -------- | ----------------------- | ---- | -------------------------------------- |
| msg | NdefMessage | 是 | NDEF Message数据对象。 | | msg | [NdefMessage](#ndefmessage9) | 是 | NDEF Message数据对象。 |
| callback | AsyncCallback\<void> | 是 | 回调函数。 | | callback | AsyncCallback\<void> | 是 | 回调函数。 |
**错误码:** **错误码:**
以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md) 以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md)
| 错误码ID | 错误信息| | 错误码ID | 错误信息|
| ------- | -------| | ------- | -------|
| 3100201 | Tag running state is abnormal in service. | | 3100201 | Tag running state is abnormal in service. |
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
...@@ -704,17 +734,20 @@ canSetReadOnly(): boolean ...@@ -704,17 +734,20 @@ canSetReadOnly(): boolean
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
**返回值:** **返回值:**
| **类型** | **说明** | | **类型** | **说明** |
| ------------------ | --------------------------| | ------------------ | --------------------------|
| boolean| true: NDEF标签可设置为只读, false: NDEF标签不可设置为只读。 | | boolean| true: NDEF标签可设置为只读, false: NDEF标签不可设置为只读。 |
**错误码:** **错误码:**
以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md) 以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md)
| 错误码ID | 错误信息| | 错误码ID | 错误信息|
| ------- | -------| | ------- | -------|
| 3100201 | Tag running state is abnormal in service. | | 3100201 | Tag running state is abnormal in service. |
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
...@@ -734,12 +767,14 @@ setReadOnly(): Promise\<void> ...@@ -734,12 +767,14 @@ setReadOnly(): Promise\<void>
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
**错误码:** **错误码:**
以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md) 以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md)
| 错误码ID | 错误信息| | 错误码ID | 错误信息|
| ------- | -------| | ------- | -------|
| 3100201 | Tag running state is abnormal in service. | | 3100201 | Tag running state is abnormal in service. |
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
...@@ -775,17 +810,20 @@ setReadOnly(callback: AsyncCallback\<void>): void ...@@ -775,17 +810,20 @@ setReadOnly(callback: AsyncCallback\<void>): void
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | -------------------------------------- | | -------- | ----------------------- | ---- | -------------------------------------- |
| callback | AsyncCallback\<void> | 是 | 回调函数。 | | callback | AsyncCallback\<void> | 是 | 回调函数。 |
**错误码:** **错误码:**
以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md) 以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md)
| 错误码ID | 错误信息| | 错误码ID | 错误信息|
| ------- | -------| | ------- | -------|
| 3100201 | Tag running state is abnormal in service. | | 3100201 | Tag running state is abnormal in service. |
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
...@@ -814,23 +852,26 @@ try { ...@@ -814,23 +852,26 @@ try {
### NdefTag.getNdefTagTypeString<sup>9+</sup> ### NdefTag.getNdefTagTypeString<sup>9+</sup>
getNdefTagTypeString(type: [NfcForumType](js-apis-nfcTag.md#nfcforumtype9)): string getNdefTagTypeString(type: [tag.NfcForumType](js-apis-nfcTag.md#nfcforumtype9)): string
将NFC论坛类型,转换为NFC论坛中定义的字符串描述。 将NFC论坛类型,转换为NFC论坛中定义的字符串描述。
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | -------------------------------------- | | -------- | ----------------------- | ---- | -------------------------------------- |
| type | [NfcForumType](js-apis-nfcTag.md#nfcforumtype9) | 是 | NDEF标签类型,包括NFC FORUM TYPE 1/2/3/4等。 | | type | [tag.NfcForumType](js-apis-nfcTag.md#nfcforumtype9) | 是 | NDEF标签类型,包括NFC FORUM TYPE 1/2/3/4等。 |
**返回值:** **返回值:**
| **类型** | **说明** | | **类型** | **说明** |
| ------------------ | --------------------------| | ------------------ | --------------------------|
| string | NFC论坛类型的字符串描述。| | string | NFC论坛类型的字符串描述。|
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
...@@ -846,7 +887,7 @@ try { ...@@ -846,7 +887,7 @@ try {
## MifareClassicTag<sup>9+</sup> ## MifareClassicTag<sup>9+</sup>
MifareClassicTag提供对MIFARE Classic属性和I/O操作的访问,继承自TagSession MifareClassicTag提供对MIFARE Classic属性和I/O操作的访问,继承自[TagSession](js-apis-tagSession.md)
TagSession是所有NFC Tag技术类型的基类, 提供建立连接和发送数据等共同接口。具体请参见[TagSession](js-apis-tagSession.md) TagSession是所有NFC Tag技术类型的基类, 提供建立连接和发送数据等共同接口。具体请参见[TagSession](js-apis-tagSession.md)
...@@ -863,6 +904,7 @@ authenticateSector(sectorIndex: number, key: number[], isKeyA: boolean): Promise ...@@ -863,6 +904,7 @@ authenticateSector(sectorIndex: number, key: number[], isKeyA: boolean): Promise
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | -------------------------------------- | | -------- | ----------------------- | ---- | -------------------------------------- |
| sectorIndex | number | 是 | 待验证的扇区索引,从0开始。 | | sectorIndex | number | 是 | 待验证的扇区索引,从0开始。 |
...@@ -870,12 +912,14 @@ authenticateSector(sectorIndex: number, key: number[], isKeyA: boolean): Promise ...@@ -870,12 +912,14 @@ authenticateSector(sectorIndex: number, key: number[], isKeyA: boolean): Promise
| isKeyA | boolean | 是 | isKeyA标志。true 表示KeyA,false 表示KeyB。| | isKeyA | boolean | 是 | isKeyA标志。true 表示KeyA,false 表示KeyB。|
**错误码:** **错误码:**
以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md) 以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md)
| 错误码ID | 错误信息| | 错误码ID | 错误信息|
| ------- | -------| | ------- | -------|
| 3100201 | Tag running state is abnormal in service. | | 3100201 | Tag running state is abnormal in service. |
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
...@@ -913,6 +957,7 @@ authenticateSector(sectorIndex: number, key: number[], isKeyA: boolean, callback ...@@ -913,6 +957,7 @@ authenticateSector(sectorIndex: number, key: number[], isKeyA: boolean, callback
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | -------------------------------------- | | -------- | ----------------------- | ---- | -------------------------------------- |
| sectorIndex | number | 是 | 待验证的扇区索引,从0开始。 | | sectorIndex | number | 是 | 待验证的扇区索引,从0开始。 |
...@@ -921,6 +966,7 @@ authenticateSector(sectorIndex: number, key: number[], isKeyA: boolean, callback ...@@ -921,6 +966,7 @@ authenticateSector(sectorIndex: number, key: number[], isKeyA: boolean, callback
| callback | AsyncCallback\<void> | 是 | 回调函数。| | callback | AsyncCallback\<void> | 是 | 回调函数。|
**错误码:** **错误码:**
以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md) 以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md)
| 错误码ID | 错误信息| | 错误码ID | 错误信息|
| ------- | -------| | ------- | -------|
...@@ -966,22 +1012,26 @@ readSingleBlock(blockIndex: number): Promise\<number[]> ...@@ -966,22 +1012,26 @@ readSingleBlock(blockIndex: number): Promise\<number[]>
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | -------------------------------------- | | -------- | ----------------------- | ---- | -------------------------------------- |
| blockIndex | number | 是 | 要读取的块索引,从0开始。 | | blockIndex | number | 是 | 要读取的块索引,从0开始。 |
**返回值:** **返回值:**
| **类型** | **说明** | | **类型** | **说明** |
| ------------------ | --------------------------| | ------------------ | --------------------------|
| Promise\<number[]> | 读取的块数据。 | | Promise\<number[]> | 读取的块数据。 |
**错误码:** **错误码:**
以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md) 以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md)
| 错误码ID | 错误信息| | 错误码ID | 错误信息|
| ------- | -------| | ------- | -------|
| 3100201 | Tag running state is abnormal in service. | | 3100201 | Tag running state is abnormal in service. |
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
...@@ -1018,18 +1068,21 @@ readSingleBlock(blockIndex: number, callback: AsyncCallback\<number[]>): void ...@@ -1018,18 +1068,21 @@ readSingleBlock(blockIndex: number, callback: AsyncCallback\<number[]>): void
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | -------------------------------------- | | -------- | ----------------------- | ---- | -------------------------------------- |
| blockIndex | number | 是 | 要读取的块索引,从0开始。 | | blockIndex | number | 是 | 要读取的块索引,从0开始。 |
| callback | AsyncCallback\<number[]> | 是 | 回调函数,返回读取到的数据。 | | callback | AsyncCallback\<number[]> | 是 | 回调函数,返回读取到的数据。 |
**错误码:** **错误码:**
以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md) 以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md)
| 错误码ID | 错误信息| | 错误码ID | 错误信息|
| ------- | -------| | ------- | -------|
| 3100201 | Tag running state is abnormal in service. | | 3100201 | Tag running state is abnormal in service. |
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
...@@ -1068,18 +1121,21 @@ writeSingleBlock(blockIndex: number, data: number[]): Promise\<void> ...@@ -1068,18 +1121,21 @@ writeSingleBlock(blockIndex: number, data: number[]): Promise\<void>
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | -------------------------------------- | | -------- | ----------------------- | ---- | -------------------------------------- |
| blockIndex | number | 是 | 要写入的块索引,从0开始。 | | blockIndex | number | 是 | 要写入的块索引,从0开始。 |
| data | number[] | 是 | 要写入的数据,大小必须是16个字节。 | | data | number[] | 是 | 要写入的数据,大小必须是16个字节。 |
**错误码:** **错误码:**
以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md) 以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md)
| 错误码ID | 错误信息| | 错误码ID | 错误信息|
| ------- | -------| | ------- | -------|
| 3100201 | Tag running state is abnormal in service. | | 3100201 | Tag running state is abnormal in service. |
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
...@@ -1095,7 +1151,8 @@ if (!mifareClassic.isTagConnected()) { ...@@ -1095,7 +1151,8 @@ if (!mifareClassic.isTagConnected()) {
try { try {
let blockIndex = 1; // change it to be correct index. let blockIndex = 1; // change it to be correct index.
let rawData = [0x01, 0x02, ..., 0x0F, 0x10]; // MUST be 16 bytes, change it to be correct data. let rawData = [0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A,
0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10]; // MUST be 16 bytes, change it to be correct data.
mifareClassic.writeSingleBlock(blockIndex, rawData).then(() => { mifareClassic.writeSingleBlock(blockIndex, rawData).then(() => {
console.log("mifareClassic writeSingleBlock Promise success."); console.log("mifareClassic writeSingleBlock Promise success.");
}).catch((err)=> { }).catch((err)=> {
...@@ -1117,6 +1174,7 @@ writeSingleBlock(blockIndex: number, data: number[], callback: AsyncCallback\<vo ...@@ -1117,6 +1174,7 @@ writeSingleBlock(blockIndex: number, data: number[], callback: AsyncCallback\<vo
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | -------------------------------------- | | -------- | ----------------------- | ---- | -------------------------------------- |
| blockIndex | number | 是 | 要写入的块索引,从0开始。 | | blockIndex | number | 是 | 要写入的块索引,从0开始。 |
...@@ -1124,12 +1182,14 @@ writeSingleBlock(blockIndex: number, data: number[], callback: AsyncCallback\<vo ...@@ -1124,12 +1182,14 @@ writeSingleBlock(blockIndex: number, data: number[], callback: AsyncCallback\<vo
| callback | AsyncCallback\<void> | 是 | 回调函数。 | | callback | AsyncCallback\<void> | 是 | 回调函数。 |
**错误码:** **错误码:**
以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md) 以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md)
| 错误码ID | 错误信息| | 错误码ID | 错误信息|
| ------- | -------| | ------- | -------|
| 3100201 | Tag running state is abnormal in service. | | 3100201 | Tag running state is abnormal in service. |
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
...@@ -1145,7 +1205,8 @@ if (!mifareClassic.isTagConnected()) { ...@@ -1145,7 +1205,8 @@ if (!mifareClassic.isTagConnected()) {
try { try {
let blockIndex = 1; // change it to be correct index. let blockIndex = 1; // change it to be correct index.
let rawData = [0x01, 0x02, ..., 0x15, 0x16]; // MUST be 16 bytes, change it to be correct data. let rawData = [0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A,
0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10]; // MUST be 16 bytes, change it to be correct data.
mifareClassic.writeSingleBlock(blockIndex, rawData, (err)=> { mifareClassic.writeSingleBlock(blockIndex, rawData, (err)=> {
if (err) { if (err) {
console.log("mifareClassic writeSingleBlock AsyncCallback err: " + err); console.log("mifareClassic writeSingleBlock AsyncCallback err: " + err);
...@@ -1169,18 +1230,21 @@ incrementBlock(blockIndex: number, value: number): Promise\<void> ...@@ -1169,18 +1230,21 @@ incrementBlock(blockIndex: number, value: number): Promise\<void>
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | -------------------------------------- | | -------- | ----------------------- | ---- | -------------------------------------- |
| blockIndex | number | 是 | 要指定增加的块索引,从0开始。 | | blockIndex | number | 是 | 要指定增加的块索引,从0开始。 |
| value | number | 是 | 要指定增加的数据,非负数。 | | value | number | 是 | 要指定增加的数据,非负数。 |
**错误码:** **错误码:**
以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md) 以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md)
| 错误码ID | 错误信息| | 错误码ID | 错误信息|
| ------- | -------| | ------- | -------|
| 3100201 | Tag running state is abnormal in service. | | 3100201 | Tag running state is abnormal in service. |
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
...@@ -1218,6 +1282,7 @@ incrementBlock(blockIndex: number, value: number, callback: AsyncCallback\<void> ...@@ -1218,6 +1282,7 @@ incrementBlock(blockIndex: number, value: number, callback: AsyncCallback\<void>
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | -------------------------------------- | | -------- | ----------------------- | ---- | -------------------------------------- |
| blockIndex | number | 是 | 要被运算的块索引,从0开始。 | | blockIndex | number | 是 | 要被运算的块索引,从0开始。 |
...@@ -1225,12 +1290,14 @@ incrementBlock(blockIndex: number, value: number, callback: AsyncCallback\<void> ...@@ -1225,12 +1290,14 @@ incrementBlock(blockIndex: number, value: number, callback: AsyncCallback\<void>
| callback | AsyncCallback\<void> | 是 | 回调函数。 | | callback | AsyncCallback\<void> | 是 | 回调函数。 |
**错误码:** **错误码:**
以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md) 以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md)
| 错误码ID | 错误信息| | 错误码ID | 错误信息|
| ------- | -------| | ------- | -------|
| 3100201 | Tag running state is abnormal in service. | | 3100201 | Tag running state is abnormal in service. |
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
...@@ -1270,18 +1337,21 @@ decrementBlock(blockIndex: number, value: number): Promise\<void> ...@@ -1270,18 +1337,21 @@ decrementBlock(blockIndex: number, value: number): Promise\<void>
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | -------------------------------------- | | -------- | ----------------------- | ---- | -------------------------------------- |
| blockIndex | number | 是 | 要被运算的块索引,从0开始。 | | blockIndex | number | 是 | 要被运算的块索引,从0开始。 |
| value | number | 是 | 要减少的数值,非负数。 | | value | number | 是 | 要减少的数值,非负数。 |
**错误码:** **错误码:**
以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md) 以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md)
| 错误码ID | 错误信息| | 错误码ID | 错误信息|
| ------- | -------| | ------- | -------|
| 3100201 | Tag running state is abnormal in service. | | 3100201 | Tag running state is abnormal in service. |
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
...@@ -1319,6 +1389,7 @@ decrementBlock(blockIndex: number, value: number, callback: AsyncCallback\<void> ...@@ -1319,6 +1389,7 @@ decrementBlock(blockIndex: number, value: number, callback: AsyncCallback\<void>
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | -------------------------------------- | | -------- | ----------------------- | ---- | -------------------------------------- |
| blockIndex | number | 是 | 要被运算的块索引,从0开始。 | | blockIndex | number | 是 | 要被运算的块索引,从0开始。 |
...@@ -1326,12 +1397,14 @@ decrementBlock(blockIndex: number, value: number, callback: AsyncCallback\<void> ...@@ -1326,12 +1397,14 @@ decrementBlock(blockIndex: number, value: number, callback: AsyncCallback\<void>
| callback | AsyncCallback\<void> | 是 | 回调函数。 | | callback | AsyncCallback\<void> | 是 | 回调函数。 |
**错误码:** **错误码:**
以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md) 以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md)
| 错误码ID | 错误信息| | 错误码ID | 错误信息|
| ------- | -------| | ------- | -------|
| 3100201 | Tag running state is abnormal in service. | | 3100201 | Tag running state is abnormal in service. |
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
...@@ -1371,17 +1444,20 @@ transferToBlock(blockIndex: number): Promise\<void> ...@@ -1371,17 +1444,20 @@ transferToBlock(blockIndex: number): Promise\<void>
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | -------------------------------------- | | -------- | ----------------------- | ---- | -------------------------------------- |
| blockIndex | number | 是 | 被操作的块的索引,从0开始。 | | blockIndex | number | 是 | 被操作的块的索引,从0开始。 |
**错误码:** **错误码:**
以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md) 以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md)
| 错误码ID | 错误信息| | 错误码ID | 错误信息|
| ------- | -------| | ------- | -------|
| 3100201 | Tag running state is abnormal in service. | | 3100201 | Tag running state is abnormal in service. |
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
...@@ -1418,18 +1494,21 @@ transferToBlock(blockIndex: number, callback: AsyncCallback\<void>): void ...@@ -1418,18 +1494,21 @@ transferToBlock(blockIndex: number, callback: AsyncCallback\<void>): void
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | -------------------------------------- | | -------- | ----------------------- | ---- | -------------------------------------- |
| blockIndex | number | 是 | 被操作的块的索引,从0开始。 | | blockIndex | number | 是 | 被操作的块的索引,从0开始。 |
| callback | AsyncCallback\<void> | 是 | 回调函数。 | | callback | AsyncCallback\<void> | 是 | 回调函数。 |
**错误码:** **错误码:**
以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md) 以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md)
| 错误码ID | 错误信息| | 错误码ID | 错误信息|
| ------- | -------| | ------- | -------|
| 3100201 | Tag running state is abnormal in service. | | 3100201 | Tag running state is abnormal in service. |
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
...@@ -1468,17 +1547,20 @@ restoreFromBlock(blockIndex: number): Promise\<void> ...@@ -1468,17 +1547,20 @@ restoreFromBlock(blockIndex: number): Promise\<void>
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | -------------------------------------- | | -------- | ----------------------- | ---- | -------------------------------------- |
| blockIndex | number | 是 | 被操作的块的索引,从0开始。| | blockIndex | number | 是 | 被操作的块的索引,从0开始。|
**错误码:** **错误码:**
以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md) 以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md)
| 错误码ID | 错误信息| | 错误码ID | 错误信息|
| ------- | -------| | ------- | -------|
| 3100201 | Tag running state is abnormal in service. | | 3100201 | Tag running state is abnormal in service. |
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
...@@ -1515,18 +1597,21 @@ restoreFromBlock(blockIndex: number, callback: AsyncCallback\<void>): void ...@@ -1515,18 +1597,21 @@ restoreFromBlock(blockIndex: number, callback: AsyncCallback\<void>): void
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | -------------------------------------- | | -------- | ----------------------- | ---- | -------------------------------------- |
| blockIndex | number | 是 | 被操作的块的索引,从0开始。 | | blockIndex | number | 是 | 被操作的块的索引,从0开始。 |
| callback | AsyncCallback\<void> | 是 | 回调函数。| | callback | AsyncCallback\<void> | 是 | 回调函数。|
**错误码:** **错误码:**
以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md) 以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md)
| 错误码ID | 错误信息| | 错误码ID | 错误信息|
| ------- | -------| | ------- | -------|
| 3100201 | Tag running state is abnormal in service. | | 3100201 | Tag running state is abnormal in service. |
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
...@@ -1563,11 +1648,13 @@ getSectorCount(): number ...@@ -1563,11 +1648,13 @@ getSectorCount(): number
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
**返回值:** **返回值:**
| **类型** | **说明** | | **类型** | **说明** |
| ------------------ | --------------------------| | ------------------ | --------------------------|
| number | 标签中的扇区数量。| | number | 标签中的扇区数量。|
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
...@@ -1585,16 +1672,19 @@ getBlockCountInSector(sectorIndex: number): number ...@@ -1585,16 +1672,19 @@ getBlockCountInSector(sectorIndex: number): number
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | -------------------------------------- | | -------- | ----------------------- | ---- | -------------------------------------- |
| sectorIndex | number | 是 | 扇区序号,从0开始。| | sectorIndex | number | 是 | 扇区序号,从0开始。|
**返回值:** **返回值:**
| **类型** | **说明** | | **类型** | **说明** |
| ------------------ | --------------------------| | ------------------ | --------------------------|
| number | 该扇区内的块数量。| | number | 该扇区内的块数量。|
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
...@@ -1611,18 +1701,20 @@ try { ...@@ -1611,18 +1701,20 @@ try {
### MifareClassicTag.getType<sup>9+</sup> ### MifareClassicTag.getType<sup>9+</sup>
getType(): [MifareClassicType](js-apis-nfcTag.md#mifareclassictype9) getType(): [tag.MifareClassicType](js-apis-nfcTag.md#mifareclassictype9)
获取MIFARE Classic标签的类型。 获取MIFARE Classic标签的类型。
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
**返回值:** **返回值:**
| **类型** | **说明** | | **类型** | **说明** |
| ------------------ | --------------------------| | ------------------ | --------------------------|
| [MifareClassicType](js-apis-nfcTag.md#mifareclassictype9) | MifareClassic标签的类型。| | [tag.MifareClassicType](js-apis-nfcTag.md#mifareclassictype9) | MifareClassic标签的类型。|
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
...@@ -1640,11 +1732,13 @@ getTagSize(): number ...@@ -1640,11 +1732,13 @@ getTagSize(): number
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
**返回值:** **返回值:**
| **类型** | **说明** | | **类型** | **说明** |
| ------------------ | --------------------------| | ------------------ | --------------------------|
| number | 标签的大小,单位为字节,请参见[MifareClassicSize](js-apis-nfcTag.md#mifareclassicsize9)。| | number | 标签的大小,单位为字节,请参见[MifareClassicSize](js-apis-nfcTag.md#mifareclassicsize9)。|
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
...@@ -1662,11 +1756,13 @@ isEmulatedTag(): boolean ...@@ -1662,11 +1756,13 @@ isEmulatedTag(): boolean
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
**返回值:** **返回值:**
| **类型** | **说明** | | **类型** | **说明** |
| ------------------ | --------------------------| | ------------------ | --------------------------|
| boolean |检查结果,true: 是;false:否。 | | boolean |检查结果,true: 是;false:否。 |
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
...@@ -1684,16 +1780,19 @@ getBlockIndex(sectorIndex: number): number ...@@ -1684,16 +1780,19 @@ getBlockIndex(sectorIndex: number): number
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | -------------------------------------- | | -------- | ----------------------- | ---- | -------------------------------------- |
| sectorIndex | number | 是 | 扇区序号,从0开始。 | | sectorIndex | number | 是 | 扇区序号,从0开始。 |
**返回值:** **返回值:**
| **类型** | **说明** | | **类型** | **说明** |
| ------------------ | --------------------------| | ------------------ | --------------------------|
| number | 该扇区内的第一个块的序号,从0开始。 | | number | 该扇区内的第一个块的序号,从0开始。 |
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
...@@ -1714,21 +1813,22 @@ getSectorIndex(blockIndex: number): number ...@@ -1714,21 +1813,22 @@ getSectorIndex(blockIndex: number): number
获取包含指定块号的扇区序号。 获取包含指定块号的扇区序号。
**需要权限**:ohos.permission.NFC_TAG
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | -------------------------------------- | | -------- | ----------------------- | ---- | -------------------------------------- |
| blockIndex | number | 是 | 块序号,从0开始。 | | blockIndex | number | 是 | 块序号,从0开始。 |
**返回值:** **返回值:**
| **类型** | **说明** | | **类型** | **说明** |
| ------------------ | --------------------------| | ------------------ | --------------------------|
| number | 扇区序号,从0开始。 | | number | 扇区序号,从0开始。 |
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
...@@ -1768,17 +1868,20 @@ readMultiplePages(pageIndex: number): Promise\<number[]> ...@@ -1768,17 +1868,20 @@ readMultiplePages(pageIndex: number): Promise\<number[]>
| pageIndex | number | 是 | 要读取页面的索引,从0开始。 | | pageIndex | number | 是 | 要读取页面的索引,从0开始。 |
**返回值:** **返回值:**
| **类型** | **说明** | | **类型** | **说明** |
| ------------------ | --------------------------| | ------------------ | --------------------------|
| Promise\<number[]> | 读取的4页的数据,共16字节。 | | Promise\<number[]> | 读取的4页的数据,共16字节。 |
**错误码:** **错误码:**
以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md) 以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md)
| 错误码ID | 错误信息| | 错误码ID | 错误信息|
| ------- | -------| | ------- | -------|
| 3100201 | Tag running state is abnormal in service. | | 3100201 | Tag running state is abnormal in service. |
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
...@@ -1816,18 +1919,21 @@ readMultiplePages(pageIndex: number, callback: AsyncCallback\<number[]>): void ...@@ -1816,18 +1919,21 @@ readMultiplePages(pageIndex: number, callback: AsyncCallback\<number[]>): void
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | -------------------------------------- | | -------- | ----------------------- | ---- | -------------------------------------- |
| pageIndex | number | 是 | 要读取页面的索引,从0开始。 | | pageIndex | number | 是 | 要读取页面的索引,从0开始。 |
| callback | AsyncCallback\<number[]> | 是 | 回调函数,返回读取到的数据,共16字节。 | | callback | AsyncCallback\<number[]> | 是 | 回调函数,返回读取到的数据,共16字节。 |
**错误码:** **错误码:**
以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md) 以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md)
| 错误码ID | 错误信息| | 错误码ID | 错误信息|
| ------- | -------| | ------- | -------|
| 3100201 | Tag running state is abnormal in service. | | 3100201 | Tag running state is abnormal in service. |
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
...@@ -1866,18 +1972,21 @@ writeSinglePage(pageIndex: number, data: number[]): Promise\<void> ...@@ -1866,18 +1972,21 @@ writeSinglePage(pageIndex: number, data: number[]): Promise\<void>
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | -------------------------------------- | | -------- | ----------------------- | ---- | -------------------------------------- |
| pageIndex | number | 是 | 要写入页面的索引,从0开始。 | | pageIndex | number | 是 | 要写入页面的索引,从0开始。 |
| data | number[] | 是 | 要写入页面的数据内容,必须是4个字节大小。 | | data | number[] | 是 | 要写入页面的数据内容,必须是4个字节大小。 |
**错误码:** **错误码:**
以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md) 以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md)
| 错误码ID | 错误信息| | 错误码ID | 错误信息|
| ------- | -------| | ------- | -------|
| 3100201 | Tag running state is abnormal in service. | | 3100201 | Tag running state is abnormal in service. |
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
...@@ -1915,6 +2024,7 @@ writeSinglePage(pageIndex: number, data: number[], callback: AsyncCallback\<void ...@@ -1915,6 +2024,7 @@ writeSinglePage(pageIndex: number, data: number[], callback: AsyncCallback\<void
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | ------------------------ | | -------- | ----------------------- | ---- | ------------------------ |
| pageIndex | number | 是 | 要写入页面的索引,从0开始。 | | pageIndex | number | 是 | 要写入页面的索引,从0开始。 |
...@@ -1922,12 +2032,14 @@ writeSinglePage(pageIndex: number, data: number[], callback: AsyncCallback\<void ...@@ -1922,12 +2032,14 @@ writeSinglePage(pageIndex: number, data: number[], callback: AsyncCallback\<void
| callback|AsyncCallback\<void> |是| 回调函数。 | | callback|AsyncCallback\<void> |是| 回调函数。 |
**错误码:** **错误码:**
以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md) 以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md)
| 错误码ID | 错误信息| | 错误码ID | 错误信息|
| ------- | -------| | ------- | -------|
| 3100201 | Tag running state is abnormal in service. | | 3100201 | Tag running state is abnormal in service. |
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
...@@ -1958,18 +2070,20 @@ try { ...@@ -1958,18 +2070,20 @@ try {
### MifareUltralightTag.getType<sup>9+</sup> ### MifareUltralightTag.getType<sup>9+</sup>
getType(): MifareUltralightType getType(): [tag.MifareUltralightType](js-apis-nfcTag.md#mifareultralighttype9)
获取MIFARE Ultralight标签的类型,具体请参见 [MifareUltralightType](js-apis-nfcTag.md#mifareultralighttype9) 获取MIFARE Ultralight标签的类型。
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
**返回值:** **返回值:**
| **类型** | **说明** | | **类型** | **说明** |
| ------------------ | --------------------------| | ------------------ | --------------------------|
| MifareUltralightType | MIFARE Ultralight标签的类型,具体请参见 [MifareUltralightType](js-apis-nfcTag.md#mifareultralighttype9)。| | [tag.MifareUltralightType](js-apis-nfcTag.md#mifareultralighttype9) | MIFARE Ultralight标签的类型。|
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
...@@ -1997,11 +2111,13 @@ format(message: [NdefMessage](#ndefmessage9)): Promise\<void> ...@@ -1997,11 +2111,13 @@ format(message: [NdefMessage](#ndefmessage9)): Promise\<void>
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | -------------------------------------- | | -------- | ----------------------- | ---- | -------------------------------------- |
| message | [NdefMessage](#ndefmessage9) | 是 | 格式化成功时要写入的NDEF消息。可以为null,为null时仅格式化标签,不写入内容。 | | message | [NdefMessage](#ndefmessage9) | 是 | 格式化成功时要写入的NDEF消息。可以为null,为null时仅格式化标签,不写入内容。 |
**错误码:** **错误码:**
以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md) 以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md)
| 错误码ID | 错误信息| | 错误码ID | 错误信息|
| ------- | -------| | ------- | -------|
...@@ -2048,17 +2164,20 @@ format(message: [NdefMessage](#ndefmessage9), callback: AsyncCallback\<void>): v ...@@ -2048,17 +2164,20 @@ format(message: [NdefMessage](#ndefmessage9), callback: AsyncCallback\<void>): v
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | -------------------------------------- | | -------- | ----------------------- | ---- | -------------------------------------- |
| message | [NdefMessage](#ndefmessage9) | 是 | 格式化成功时要写入的Ndef消息。可以为null,为null时仅格式化标签,不写入内容。 | | message | [NdefMessage](#ndefmessage9) | 是 | 格式化成功时要写入的Ndef消息。可以为null,为null时仅格式化标签,不写入内容。 |
**返回值:** **返回值:**
| **类型** | **说明** | | **类型** | **说明** |
| ------------------ | --------------------------| | ------------------ | --------------------------|
| callback: AsyncCallback\<void> | 回调函数。 | | callback: AsyncCallback\<void> | 回调函数。 |
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
...@@ -2100,17 +2219,20 @@ formatReadOnly(message: [NdefMessage](#ndefmessage9)): Promise\<void> ...@@ -2100,17 +2219,20 @@ formatReadOnly(message: [NdefMessage](#ndefmessage9)): Promise\<void>
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | -------------------------------------- | | -------- | ----------------------- | ---- | -------------------------------------- |
| message | [NdefMessage](#ndefmessage9) | 是 | 格式化成功时要写入的NDEF消息。可以为null,为null时仅格式化标签,不写入内容。 | | message | [NdefMessage](#ndefmessage9) | 是 | 格式化成功时要写入的NDEF消息。可以为null,为null时仅格式化标签,不写入内容。 |
**错误码:** **错误码:**
以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md) 以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md)
| 错误码ID | 错误信息| | 错误码ID | 错误信息|
| ------- | -------| | ------- | -------|
| 3100201 | Tag running state is abnormal in service. | | 3100201 | Tag running state is abnormal in service. |
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
...@@ -2150,17 +2272,20 @@ formatReadOnly(message: [NdefMessage](#ndefmessage9), callback: AsyncCallback\<v ...@@ -2150,17 +2272,20 @@ formatReadOnly(message: [NdefMessage](#ndefmessage9), callback: AsyncCallback\<v
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | -------------------------------------- | | -------- | ----------------------- | ---- | -------------------------------------- |
| message | [NdefMessage](#ndefmessage9) | 是 | 格式化成功时要写入的NDEF消息。可以为null,为null时仅格式化标签,不写入内容。| | message | [NdefMessage](#ndefmessage9) | 是 | 格式化成功时要写入的NDEF消息。可以为null,为null时仅格式化标签,不写入内容。|
**返回值:** **返回值:**
| **类型** | **说明** | | **类型** | **说明** |
| ------------------ | --------------------------| | ------------------ | --------------------------|
| callback: AsyncCallback\<void> | 回调函数。 | | callback: AsyncCallback\<void> | 回调函数。 |
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
......
...@@ -30,18 +30,20 @@ getTagInfo(): tag.TagInfo ...@@ -30,18 +30,20 @@ getTagInfo(): tag.TagInfo
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
**返回值:** **返回值:**
| **类型** | **说明** | | **类型** | **说明** |
| ------------------ | --------------------------| | ------------------ | --------------------------|
| TagInfo | NFC服务所提供的Tag数据对象。 | | TagInfo | NFC服务所提供的Tag数据对象。 |
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
// see 'tag.TagInfo' at 'js-apis-nfcTag.md', tagInfo is an Object given by nfc service when tag is dispatched. // see 'tag.TagInfo' at 'js-apis-nfcTag.md', tagInfo is an Object given by nfc service when tag is dispatched.
// the folowing getXXX, can be one of getIsoDep, getNdef, getMifareClassic, ... // the folowing getXXX, can be one of getIsoDep, getNdef, getMifareClassic, ...
let tagInfo = tag.getXXX(tagInfo).getTagInfo(); let tagInfo = tag.getIsoDep(tagInfo).getTagInfo();
console.log("tag tagInfo: " + tagInfo); console.log("tag tagInfo: " + tagInfo);
``` ```
...@@ -56,18 +58,20 @@ connectTag(): boolean; ...@@ -56,18 +58,20 @@ connectTag(): boolean;
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
**返回值:** **返回值:**
| **类型** | **说明** | | **类型** | **说明** |
| ------------------ | --------------------------| | ------------------ | --------------------------|
| boolean | 连接建立成功返回true,失败返回false。 | | boolean | 连接建立成功返回true,失败返回false。 |
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
// see 'tag.TagInfo' at 'js-apis-nfcTag.md', tagInfo is an Object given by nfc service when tag is dispatched. // see 'tag.TagInfo' at 'js-apis-nfcTag.md', tagInfo is an Object given by nfc service when tag is dispatched.
// the folowing getXXX, can be one of getIsoDep, getNdef, getMifareClassic, ... // the folowing getXXX, can be one of getIsoDep, getNdef, getMifareClassic, ...
let connectStatus = tag.getXXX(tagInfo).connectTag(); let connectStatus = tag.getIsoDep(tagInfo).connectTag();
console.log("connectStatus: " + connectStatus); console.log("connectStatus: " + connectStatus);
``` ```
...@@ -82,13 +86,14 @@ reset(): void ...@@ -82,13 +86,14 @@ reset(): void
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
// see 'tag.TagInfo' at 'js-apis-nfcTag.md', tagInfo is an Object given by nfc service when tag is dispatched. // see 'tag.TagInfo' at 'js-apis-nfcTag.md', tagInfo is an Object given by nfc service when tag is dispatched.
// the folowing getXXX, can be one of getIsoDep, getNdef, getMifareClassic, ... // the folowing getXXX, can be one of getIsoDep, getNdef, getMifareClassic, ...
tag.getXXX(tagInfo).reset(); tag.getIsoDep(tagInfo).reset();
``` ```
### tagSession.isTagConnected ### tagSession.isTagConnected
...@@ -102,18 +107,20 @@ isTagConnected(): boolean ...@@ -102,18 +107,20 @@ isTagConnected(): boolean
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
**返回值:** **返回值:**
| **类型** | **说明** | | **类型** | **说明** |
| ------------------ | --------------------------| | ------------------ | --------------------------|
| boolean | 已建立连接返回 true,未建立连接返回false。 | | boolean | 已建立连接返回 true,未建立连接返回false。 |
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
// see 'tag.TagInfo' at 'js-apis-nfcTag.md', tagInfo is an Object given by nfc service when tag is dispatched. // see 'tag.TagInfo' at 'js-apis-nfcTag.md', tagInfo is an Object given by nfc service when tag is dispatched.
// the folowing getXXX, can be one of getIsoDep, getNdef, getMifareClassic, ... // the folowing getXXX, can be one of getIsoDep, getNdef, getMifareClassic, ...
let isTagConnected = tag.getXXX(tagInfo).isTagConnected(); let isTagConnected = tag.getIsoDep(tagInfo).isTagConnected();
console.log("isTagConnected: " + isTagConnected); console.log("isTagConnected: " + isTagConnected);
``` ```
...@@ -128,6 +135,7 @@ getMaxSendLength(): number ...@@ -128,6 +135,7 @@ getMaxSendLength(): number
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
**返回值:** **返回值:**
| **类型** | **说明** | | **类型** | **说明** |
| ------------------ | --------------------------| | ------------------ | --------------------------|
| number | 可以发送到标签的最大数据长度,非负数。 | | number | 可以发送到标签的最大数据长度,非负数。 |
...@@ -139,7 +147,7 @@ import tag from '@ohos.nfc.tag'; ...@@ -139,7 +147,7 @@ import tag from '@ohos.nfc.tag';
// see 'tag.TagInfo' at 'js-apis-nfcTag.md', tagInfo is an Object given by nfc service when tag is dispatched. // see 'tag.TagInfo' at 'js-apis-nfcTag.md', tagInfo is an Object given by nfc service when tag is dispatched.
// the folowing getXXX, can be one of getIsoDep, getNdef, getMifareClassic, ... // the folowing getXXX, can be one of getIsoDep, getNdef, getMifareClassic, ...
let maxSendLen = tag.getXXX(tagInfo).getMaxSendLength(); let maxSendLen = tag.getIsoDep(tagInfo).getMaxSendLength();
console.log("tag maxSendLen: " + maxSendLen); console.log("tag maxSendLen: " + maxSendLen);
``` ```
...@@ -154,18 +162,20 @@ getSendDataTimeout(): number ...@@ -154,18 +162,20 @@ getSendDataTimeout(): number
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
**返回值:** **返回值:**
| **类型** | **说明** | | **类型** | **说明** |
| ------------------ | --------------------------| | ------------------ | --------------------------|
| number | 发送数据到Tag的等待超时时间,单位是毫秒,非负数。 | | number | 发送数据到Tag的等待超时时间,单位是毫秒,非负数。 |
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
// see 'tag.TagInfo' at 'js-apis-nfcTag.md', tagInfo is an Object given by nfc service when tag is dispatched. // see 'tag.TagInfo' at 'js-apis-nfcTag.md', tagInfo is an Object given by nfc service when tag is dispatched.
// the folowing getXXX, can be one of getIsoDep, getNdef, getMifareClassic, ... // the folowing getXXX, can be one of getIsoDep, getNdef, getMifareClassic, ...
let sendDataTimeout = tag.getXXX(tagInfo).getSendDataTimeout(); let sendDataTimeout = tag.getIsoDep(tagInfo).getSendDataTimeout();
console.log("tag sendDataTimeout: " + sendDataTimeout); console.log("tag sendDataTimeout: " + sendDataTimeout);
``` ```
...@@ -180,11 +190,13 @@ setSendDataTimeout(timeout: number): boolean ...@@ -180,11 +190,13 @@ setSendDataTimeout(timeout: number): boolean
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | -------------------------------------- | | -------- | ----------------------- | ---- | -------------------------------------- |
| timeout | number | 是 | 超时时间,单位毫秒,非负值。 | | timeout | number | 是 | 超时时间,单位毫秒,非负值。 |
**返回值:** **返回值:**
| **类型** | **说明** | | **类型** | **说明** |
| ------------------ | --------------------------| | ------------------ | --------------------------|
| boolean | 设置超时时间成功返回true,设置失败返回false。 | | boolean | 设置超时时间成功返回true,设置失败返回false。 |
...@@ -198,7 +210,7 @@ import tag from '@ohos.nfc.tag'; ...@@ -198,7 +210,7 @@ import tag from '@ohos.nfc.tag';
// the folowing getXXX, can be one of getIsoDep, getNdef, getMifareClassic, ... // the folowing getXXX, can be one of getIsoDep, getNdef, getMifareClassic, ...
let timeoutMs = 700; // change it to be correct. let timeoutMs = 700; // change it to be correct.
let setStatus = tag.getXXX(tagInfo).setSendDataTimeout(timeoutMs); let setStatus = tag.getIsoDep(tagInfo).setSendDataTimeout(timeoutMs);
console.log("tag setSendDataTimeout setStatus: " + setStatus); console.log("tag setSendDataTimeout setStatus: " + setStatus);
``` ```
...@@ -210,19 +222,22 @@ sendData(data: number[]): Promise<number[]> ...@@ -210,19 +222,22 @@ sendData(data: number[]): Promise<number[]>
**需要权限**:ohos.permission.NFC_TAG **需要权限**:ohos.permission.NFC_TAG
**系统能力**:SystemCapability.Communication.NFC **系统能力**:SystemCapability.Communication.NFC.Core
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | -------------------------------------- | | -------- | ----------------------- | ---- | -------------------------------------- |
| data | number[] | 是 | 要发送的指令。每个number十六进制表示,范围是0x00~0xFF。 | | data | number[] | 是 | 要发送的指令。每个number十六进制表示,范围是0x00~0xFF。 |
**返回值:** **返回值:**
| **类型** | **说明** | | **类型** | **说明** |
| ------------------ | --------------------------| | ------------------ | --------------------------|
| Promise<number[]> | 对端Tag对指令的响应数据。每个number十六进制表示,范围是0x00~0xFF。| | Promise<number[]> | 对端Tag对指令的响应数据。每个number十六进制表示,范围是0x00~0xFF。|
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
...@@ -230,15 +245,15 @@ import tag from '@ohos.nfc.tag'; ...@@ -230,15 +245,15 @@ import tag from '@ohos.nfc.tag';
// the folowing getXXX, can be one of getIsoDep, getNdef, getMifareClassic, ... // the folowing getXXX, can be one of getIsoDep, getNdef, getMifareClassic, ...
// connect the tag at first if not connected. // connect the tag at first if not connected.
if (!tag.getXXX(tagInfo).isTagConnected()) { if (!tag.getIsoDep(tagInfo).isTagConnected()) {
if (!tag.getXXX(tagInfo).connectTag()) { if (!tag.getIsoDep(tagInfo).connectTag()) {
console.log("tagSession connectTag failed."); console.log("tagSession connectTag failed.");
return; return;
} }
} }
let cmdData = [0x01, 0x02, ...]; // change the raw data to be correct. let cmdData = [0x01, 0x02, 0x03, 0x04]; // change the raw data to be correct.
tag.getXXX(tagInfo).sendData(cmdData).then((response) => { tag.getIsoDep(tagInfo).sendData(cmdData).then((response) => {
console.log("tagSession sendData Promise response: " + response); console.log("tagSession sendData Promise response: " + response);
}).catch((err)=> { }).catch((err)=> {
console.log("tagSession sendData Promise err: " + err); console.log("tagSession sendData Promise err: " + err);
...@@ -253,15 +268,17 @@ sendData(data: number[], callback: AsyncCallback<number[]>): void ...@@ -253,15 +268,17 @@ sendData(data: number[], callback: AsyncCallback<number[]>): void
**需要权限**:ohos.permission.NFC_TAG **需要权限**:ohos.permission.NFC_TAG
**系统能力**:SystemCapability.Communication.NFC **系统能力**:SystemCapability.Communication.NFC.Core
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | -------------------------------------- | | -------- | ----------------------- | ---- | -------------------------------------- |
| data | number[] | 是 | 要发送的指令。每个number十六进制表示,范围是0x00~0xFF。 | | data | number[] | 是 | 要发送的指令。每个number十六进制表示,范围是0x00~0xFF。 |
| callback | AsyncCallback<number[]> | 是 | 回调函数,返回响应数据。每个number十六进制表示,范围是0x00~0xFF。 | | callback | AsyncCallback<number[]> | 是 | 回调函数,返回响应数据。每个number十六进制表示,范围是0x00~0xFF。 |
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
...@@ -269,15 +286,15 @@ import tag from '@ohos.nfc.tag'; ...@@ -269,15 +286,15 @@ import tag from '@ohos.nfc.tag';
// the folowing getXXX, can be one of getIsoDep, getNdef, getMifareClassic, ... // the folowing getXXX, can be one of getIsoDep, getNdef, getMifareClassic, ...
// connect the tag at first if not connected. // connect the tag at first if not connected.
if (!tag.getXXX(tagInfo).isTagConnected()) { if (!tag.getIsoDep(tagInfo).isTagConnected()) {
if (!tag.getXXX(tagInfo).connectTag()) { if (!tag.getIsoDep(tagInfo).connectTag()) {
console.log("tagSession connectTag failed."); console.log("tagSession connectTag failed.");
return; return;
} }
} }
let cmdData = [0x01, 0x02, ...]; // change the raw data to be correct. let cmdData = [0x01, 0x02, 0x03, 0x04]; // change the raw data to be correct.
tag.getXXX(tagInfo).sendData(cmdData, (err, response)=> { tag.getIsoDep(tagInfo).sendData(cmdData, (err, response)=> {
if (err) { if (err) {
console.log("tagSession sendData AsyncCallback err: " + err); console.log("tagSession sendData AsyncCallback err: " + err);
} else { } else {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册