diff --git a/zh-cn/application-dev/reference/apis/js-apis-connectedTag.md b/zh-cn/application-dev/reference/apis/js-apis-connectedTag.md index 6664f4658af06b9c4bf6ba562ae0c1fc31b5c8a5..edad20e66ff3b582295cf6b782d4b74117efb93c 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-connectedTag.md +++ b/zh-cn/application-dev/reference/apis/js-apis-connectedTag.md @@ -28,6 +28,23 @@ init(): boolean | -------- | -------- | | boolean | true:初始化成功, false:初始化失败。 | +## connectedTag.initialize9+ + +initialize(): void + +初始化有源标签芯片。 + +**需要权限:** ohos.permission.NFC_TAG + +**系统能力:** SystemCapability.Communication.ConnectedTag + +**错误码:** +以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md)。 + +| 错误码ID | 错误信息| +| -------- | -------- | +| 3200101 | Connected NFC tag running state is abnormal in service. | + ## connectedTag.uninit uninit(): boolean @@ -44,6 +61,23 @@ uninit(): boolean | -------- | -------- | | boolean | true:卸载操作成功, false:卸载操作失败。 | +## connectedTag.uninitialize9+ + +uninitialize(): void + +卸载有源标签芯片资源。 + +**需要权限:** ohos.permission.NFC_TAG + +**系统能力:** SystemCapability.Communication.ConnectedTag + +**错误码:** +以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md)。 + +| 错误码ID | 错误信息| +| -------- | -------- | +| 3200101 | Connected NFC tag running state is abnormal in service. | + ## connectedTag.readNdefTag readNdefTag(): Promise<string> @@ -72,6 +106,41 @@ connectedTag.readNdefTag().then((data) => { }); ``` +## connectedTag.read9+ + +read(): Promise<number[]> + +读取有源标签内容,使用promise方式作为异步方法。 + +**需要权限:** ohos.permission.NFC_TAG + +**系统能力:** SystemCapability.Communication.ConnectedTag + +**返回值:** + +| **类型** | **说明** | +| -------- | -------- | +| Promise<number[]> | 返回读取有源标签内容。 | + +**错误码:** +以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md)。 + +| 错误码ID | 错误信息| +| -------- | -------- | +| 3200101 | Connected NFC tag running state is abnormal in service. | + +**示例:** + +```js +import connectedTag from '@ohos.connectedTag'; + +connectedTag.read().then((data) => { + console.log("connectedTag read Promise data = " + data); +}).catch((err)=> { + console.log("connectedTag read Promise err: " + err); +}); +``` + ## connectedTag.readNdefTag readNdefTag(callback: AsyncCallback<string>): void @@ -102,6 +171,43 @@ connectedTag.readNdefTag((err, data)=> { }); ``` +## connectedTag.read9+ + +read(callback: AsyncCallback<number[]>): void + +读取有源标签内容,使用AsyncCallback方式作为异步方法。 + +**需要权限:** ohos.permission.NFC_TAG + +**系统能力:** SystemCapability.Communication.ConnectedTag + +**参数:** + +| **参数名** | **类型** | **必填** | **说明** | +| -------- | -------- | -------- | -------- | +| callback | AsyncCallback<number[]> | 是 | 读取有源标签内容回调函数。 | + +**错误码:** +以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md)。 + +| 错误码ID | 错误信息| +| -------- | -------- | +| 3200101 | Connected NFC tag running state is abnormal in service. | + +**示例:** + +```js +import connectedTag from '@ohos.connectedTag'; + +connectedTag.read((err, data)=> { + if (err) { + console.log("connectedTag read AsyncCallback err: " + err); + } else { + console.log("connectedTag read AsyncCallback data: " + data); + } +}); +``` + ## connectedTag.writeNdefTag writeNdefTag(data: string): Promise<void> @@ -137,6 +243,48 @@ connectedTag.writeNdefTag(rawData).then(() => { }); ``` +## connectedTag.write9+ + +write(data: number[]): Promise<void> + +写入内容到有源标签,使用promise方式作为异步方法。 + +**需要权限:** ohos.permission.NFC_TAG + +**系统能力:** SystemCapability.Communication.ConnectedTag + +**参数:** + +| **参数名** | **类型** | **必填** | **说明** | +| -------- | -------- | -------- | -------- | +| data | number[] | 是 | 有源标签内容, 由十六进制数字组成,范围从0x00至0xFF。 | + +**返回值:** + +| **类型** | **说明** | +| -------- | -------- | +| Promise<void> | 无返回值。 | + +**错误码:** +以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md)。 + +| 错误码ID | 错误信息| +| -------- | -------- | +| 3200101 | Connected NFC tag running state is abnormal in service. | + +**示例:** + +```js +import connectedTag from '@ohos.connectedTag'; + +var rawData = [0x01, 0x02, 0x03]; // change it tobe correct. +connectedTag.write(rawData).then(() => { + console.log("connectedTag write NdefTag Promise success."); +}).catch((err)=> { + console.log("connectedTag write NdefTag Promise err: " + err); +}); +``` + ## connectedTag.writeNdefTag writeNdefTag(data: string, callback: AsyncCallback<void>): void @@ -169,6 +317,45 @@ connectedTag.writeNdefTag(rawData, (err)=> { }); ``` +## connectedTag.write9+ + +write(data: number[], callback: AsyncCallback<void>): void + +写入内容到有源标签,使用AsyncCallback方式作为异步方法。 + +**需要权限:** ohos.permission.NFC_TAG + +**系统能力:** SystemCapability.Communication.ConnectedTag + +**参数:** + +| **参数名** | **类型** | **必填** | **说明** | +| -------- | -------- | -------- | -------- | +| data | number[] | 是 | 有源标签内容, 由十六进制数字组成,范围从0x00至0xFF。 | +| callback | AsyncCallback<void> | 是 | 读取有源标签内容回调函数。 | + +**错误码:** +以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md)。 + +| 错误码ID | 错误信息| +| -------- | -------- | +| 3200101 | Connected NFC tag running state is abnormal in service. | + +**示例:** + +```js +import connectedTag from '@ohos.connectedTag'; + +var rawData = [0x01, 0x02, 0x03]; // change it tobe correct. +connectedTag.write(rawData, (err)=> { + if (err) { + console.log("connectedTag write NdefTag AsyncCallback err: " + err); + } else { + console.log("connectedTag write NdefTag AsyncCallback success."); + } +}); +``` + ## connectedTag.on('notify') on(type: "notify", callback: Callback<number>): void diff --git a/zh-cn/application-dev/reference/errorcodes/errorcode-nfc.md b/zh-cn/application-dev/reference/errorcodes/errorcode-nfc.md index 044cb9e7e7c5b0e142bc9a906111c1e5f2c77ad2..2296a97d12747fcad591d38239da32f85b75a13f 100644 --- a/zh-cn/application-dev/reference/errorcodes/errorcode-nfc.md +++ b/zh-cn/application-dev/reference/errorcodes/errorcode-nfc.md @@ -48,3 +48,20 @@ NFC服务执行Tag业务逻辑遇到错误。 4. 重新触碰读取卡片。 5. 退出应用后,重新读取卡片。 +## 3200101 + +**错误信息** + +Connected NFC tag running state is abnormal in service. + +**错误描述** + +执行有源NFC Tag业务逻辑遇到错误。 + +**可能原因** +1. 有源NFC Tag参数值和实际调用函数要求不匹配。 +2. 有源NFC Tag芯片返回错误状态或响应超时。 + +**处理步骤** +1. 检查有源NFC Tag参数是否和所调用接口匹配。 +2. 重新触碰读取卡片。