提交 cb8ab121 编写于 作者: Z zhangxiuping

Update aps description for nfc tag operations.

Signed-off-by: Nzhangxiuping <zhangxiuping@huawei.com>
上级 865515fe
...@@ -5,15 +5,94 @@ ...@@ -5,15 +5,94 @@
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:** > ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 > 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
## **声明技术**
开发Tag读写相关应用时,需要在应用的属性配置文件中,声明与NFC相关的属性值,比如,在module.json5文件中,声明下面属性值:
```js
{
"module": {
// other declared attributes.
"abilities": [
{
"skills": [
{
"actions": [
// other declared actions,
// add the nfc tag action
"ohos.nfc.tag.action.TAG_FOUND"
]
}
],
"metadata": [
{
"name": "tag-tech",
"value": "NfcA"
},
{
"name": "tag-tech",
"value": "IsoDep"
},
// add other technology if neccessary,
// such as: NfcB/NfcF/NfcV/Ndef/MifareClassic/MifareUL/NdefFormatable
]
}
],
"requestPermissions": [
"name": "ohos.permission.NFC_TAG",
"reason": "tag",
]
}
}
```
> **注意:**
1. 声明"actions"字段的内容填写,必须是"ohos.nfc.tag.action.TAG_FOUND",不能更改。
2. 声明技术时"metadata"中的"name"字段的内容填写,必须是"tag-tech",不能更改。
3. 声明技术时"metadata"中的"value"字段的内容填写,必须是"NfcA/NfcB/NfcF/NfcV/IsoDep/Ndef/MifareClassic/MifareUL/NdefFormatable"中的一个或多个。填写错误会造成解析失败。
4. 声明权限时"requestPermissions"中的"name"字段的内容填写,必须是"ohos.permission.NFC_TAG",不能更改。
## **导入模块** ## **导入模块**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
``` ```
## **tag.TagInfo**
在对相关Tag类型卡片进行读写之前,必须先获取TagInfo相关属性值,以确认设备读取到的Tag卡片支持哪些技术类型。这样Tag应用程序才能调用正确的接口和所读取到的Tag卡片进行通信。
```js
import tag from '@ohos.nfc.tag';
onCreate(want, launchParam) {
// add other code here
// want is initialized by nfc service, contains tag info for this found tag
var tagInfo = tag.getTagInfo(want);
if (tagInfo == undefined) {
console.log("no TagInfo to be created, ignore it.");
return;
}
var isNfcATag = false;
for (var i = 0; i < tagInfo.technology.length; i++) {
if (tagInfo.technology[i] == tag.NFC_A) {
isNfcATag = true;
break;
}
// also check for technology: tag.NFC_B/NFC_F/NFC_V/ISO_DEP/NDEF/MIFARE_CLASSIC/MIFARE_ULTRALIGHT/NDEF_FORMATABLE
}
if (isNfcATag) {
var nfcA = tag.getNfcATag(taginfo);
// other code to read or write this found tag.
}
// use the same code to handle for "NfcA/NfcB/NfcF/NfcV/IsoDep/Ndef/MifareClassic/MifareUL/NdefFormatable", such as:
// var isoDep = tag.getIsoDepTag(taginfo);
}
```
## tag.getNfcATag ## tag.getNfcATag
getNfcATag(tagInfo: [TagInfo](#taginfo7)): [NfcATag](js-apis-nfctech.md#nfcatag) getNfcATag(tagInfo: [TagInfo](#taginfo)): [NfcATag](js-apis-nfctech.md#nfcatag)
获取NFC A类型Tag对象,通过该对象可访问NfcA技术类型的Tag。 获取NFC A类型Tag对象,通过该对象可访问NfcA技术类型的Tag。
...@@ -29,7 +108,7 @@ getNfcATag(tagInfo: [TagInfo](#taginfo7)): [NfcATag](js-apis-nfctech.md#nfcatag) ...@@ -29,7 +108,7 @@ getNfcATag(tagInfo: [TagInfo](#taginfo7)): [NfcATag](js-apis-nfctech.md#nfcatag)
## tag.getNfcBTag ## tag.getNfcBTag
getNfcBTag(tagInfo: [TagInfo](#taginfo7)): [NfcBTag](js-apis-nfctech.md#nfcbtag) getNfcBTag(tagInfo: [TagInfo](#taginfo)): [NfcBTag](js-apis-nfctech.md#nfcbtag)
获取NFC B类型Tag对象,通过该对象可访问NfcB技术类型的Tag。 获取NFC B类型Tag对象,通过该对象可访问NfcB技术类型的Tag。
...@@ -45,7 +124,7 @@ getNfcBTag(tagInfo: [TagInfo](#taginfo7)): [NfcBTag](js-apis-nfctech.md#nfcbtag) ...@@ -45,7 +124,7 @@ getNfcBTag(tagInfo: [TagInfo](#taginfo7)): [NfcBTag](js-apis-nfctech.md#nfcbtag)
## tag.getNfcFTag ## tag.getNfcFTag
getNfcFTag(tagInfo: [TagInfo](#taginfo7)): [NfcFTag](js-apis-nfctech.md#nfcftag) getNfcFTag(tagInfo: [TagInfo](#taginfo)): [NfcFTag](js-apis-nfctech.md#nfcftag)
获取NFC F类型Tag对象,通过该对象可访问NfcF技术类型的Tag。 获取NFC F类型Tag对象,通过该对象可访问NfcF技术类型的Tag。
...@@ -61,7 +140,7 @@ getNfcFTag(tagInfo: [TagInfo](#taginfo7)): [NfcFTag](js-apis-nfctech.md#nfcftag) ...@@ -61,7 +140,7 @@ getNfcFTag(tagInfo: [TagInfo](#taginfo7)): [NfcFTag](js-apis-nfctech.md#nfcftag)
## tag.getNfcVTag ## tag.getNfcVTag
getNfcVTag(tagInfo: [TagInfo](#taginfo7)): [NfcVTag](js-apis-nfctech.md#nfcvtag) getNfcVTag(tagInfo: [TagInfo](#taginfo)): [NfcVTag](js-apis-nfctech.md#nfcvtag)
获取NFC V类型Tag对象,通过该对象可访问NfcV技术类型的Tag。 获取NFC V类型Tag对象,通过该对象可访问NfcV技术类型的Tag。
...@@ -77,11 +156,10 @@ getNfcVTag(tagInfo: [TagInfo](#taginfo7)): [NfcVTag](js-apis-nfctech.md#nfcvtag) ...@@ -77,11 +156,10 @@ getNfcVTag(tagInfo: [TagInfo](#taginfo7)): [NfcVTag](js-apis-nfctech.md#nfcvtag)
## tag.getIsoDepTag<sup>9+</sup> ## tag.getIsoDepTag<sup>9+</sup>
getIsoDepTag(tagInfo: [TagInfo](#taginfo7)): [IsoDepTag](js-apis-nfctech.md#isoDepTag9 ) getIsoDepTag(tagInfo: [TagInfo](#taginfo)): [IsoDepTag](js-apis-nfctech.md#isoDepTag9 )
获取IsoDep类型Tag对象,通过该对象可访问Iso Dep技术类型的Tag。 获取IsoDep类型Tag对象,通过该对象可访问Iso Dep技术类型的Tag。
**需要权限**:ohos.permission.NFC_TAG **需要权限**:ohos.permission.NFC_TAG
**系统能力**:SystemCapability.Communication.NFC.Core **系统能力**:SystemCapability.Communication.NFC.Core
...@@ -94,7 +172,7 @@ getIsoDepTag(tagInfo: [TagInfo](#taginfo7)): [IsoDepTag](js-apis-nfctech.md#isoD ...@@ -94,7 +172,7 @@ getIsoDepTag(tagInfo: [TagInfo](#taginfo7)): [IsoDepTag](js-apis-nfctech.md#isoD
## tag.getNdefTag<sup>9+</sup> ## tag.getNdefTag<sup>9+</sup>
getNdefTag(tagInfo: [TagInfo](#taginfo7)): [NdefTag](js-apis-nfctech.md#ndeftag9) getNdefTag(tagInfo: [TagInfo](#taginfo)): [NdefTag](js-apis-nfctech.md#ndeftag9)
获取Ndef类型Tag对象,通过该对象可访问Ndef技术类型的Tag。 获取Ndef类型Tag对象,通过该对象可访问Ndef技术类型的Tag。
...@@ -111,7 +189,7 @@ getNdefTag(tagInfo: [TagInfo](#taginfo7)): [NdefTag](js-apis-nfctech.md#ndeftag9 ...@@ -111,7 +189,7 @@ getNdefTag(tagInfo: [TagInfo](#taginfo7)): [NdefTag](js-apis-nfctech.md#ndeftag9
## tag.getMifareClassicTag<sup>9+</sup> ## tag.getMifareClassicTag<sup>9+</sup>
getMifareClassicTag(tagInfo: [TagInfo](#taginfo7)): [MifareClassicTag](js-apis-nfctech.md#mifareclassictag-9) getMifareClassicTag(tagInfo: [TagInfo](#taginfo)): [MifareClassicTag](js-apis-nfctech.md#mifareclassictag-9)
获取Mifare Classic类型Tag对象,通过该对象访问Mifare Classic技术类型的Tag。 获取Mifare Classic类型Tag对象,通过该对象访问Mifare Classic技术类型的Tag。
...@@ -127,7 +205,7 @@ getMifareClassicTag(tagInfo: [TagInfo](#taginfo7)): [MifareClassicTag](js-apis-n ...@@ -127,7 +205,7 @@ getMifareClassicTag(tagInfo: [TagInfo](#taginfo7)): [MifareClassicTag](js-apis-n
## tag.getMifareUltralightTag<sup>9+</sup> ## tag.getMifareUltralightTag<sup>9+</sup>
getMifareUltralightTag(tagInfo: [TagInfo](#taginfo7)): [MifareUltralightTag](js-apis-nfctech.md#mifareultralighttag9) getMifareUltralightTag(tagInfo: [TagInfo](#taginfo)): [MifareUltralightTag](js-apis-nfctech.md#mifareultralighttag9)
获取Mifare Ultralight类型Tag对象,通过该对象可访问Mifare Ultralight技术类型的Tag。 获取Mifare Ultralight类型Tag对象,通过该对象可访问Mifare Ultralight技术类型的Tag。
...@@ -143,7 +221,7 @@ getMifareUltralightTag(tagInfo: [TagInfo](#taginfo7)): [MifareUltralightTag](js- ...@@ -143,7 +221,7 @@ getMifareUltralightTag(tagInfo: [TagInfo](#taginfo7)): [MifareUltralightTag](js-
## tag.getNdefFormatableTag<sup>9+</sup> ## tag.getNdefFormatableTag<sup>9+</sup>
getNdefFormatableTag(tagInfo: [TagInfo](#taginfo7)): [NdefFormatableTag](js-apis-nfctech.md#ndefformatabletag9) getNdefFormatableTag(tagInfo: [TagInfo](#taginfo)): [NdefFormatableTag](js-apis-nfctech.md#ndefformatabletag9)
获取Ndef Formatable类型Tag对象,通过该对象可访问Ndef Formatable技术类型的Tag。 获取Ndef Formatable类型Tag对象,通过该对象可访问Ndef Formatable技术类型的Tag。
...@@ -157,9 +235,25 @@ getNdefFormatableTag(tagInfo: [TagInfo](#taginfo7)): [NdefFormatableTag](js-apis ...@@ -157,9 +235,25 @@ getNdefFormatableTag(tagInfo: [TagInfo](#taginfo7)): [NdefFormatableTag](js-apis
| ------------------ | --------------------------| | ------------------ | --------------------------|
| [NdefFormatableTag](js-apis-nfctech.md#ndefformatabletag) | Ndef Formatable类型Tag对象。 | | [NdefFormatableTag](js-apis-nfctech.md#ndefformatabletag) | Ndef Formatable类型Tag对象。 |
## TagInfo<sup>7+</sup> ## tag.getTagInfo<sup>9+</sup>
getTagInfo(want: Want): [TagInfo](#taginfo)
nfc服务在调度标签时给出的对象。 从Want中获取TagInfo,Want是被NFC服务初始化,包含了TagInfo所需的属性值。
**需要权限**:ohos.permission.NFC_TAG
**系统能力**:SystemCapability.Communication.NFC.Core
**返回值:**
| **类型** | **说明** |
| ------------------ | --------------------------|
| [TagInfo](#taginfo) | TagInfo对象,用于获取不同技术类型的Tag对象。 |
## TagInfo
NFC服务在读取到标签时给出的对象,通过改对象属性,应用知道该标签支持哪些技术类型,并使用匹配的技术类型来调用相关接口。
**需要权限**:ohos.permission.NFC_TAG **需要权限**:ohos.permission.NFC_TAG
...@@ -167,7 +261,117 @@ nfc服务在调度标签时给出的对象。 ...@@ -167,7 +261,117 @@ nfc服务在调度标签时给出的对象。
| **参数名** | **类型** | **说明** | | **参数名** | **类型** | **说明** |
| -------- | -------- | -------- | | -------- | -------- | -------- |
| uid<sup>9+</sup> | string | 标签的uid。 | | uid<sup>9+</sup> | number[] | 标签的uid,每个number值是十六进制表示,范围是0x00~0xFF。 |
| technology<sup>9+</sup> | number[] | 支持的技术类型。 | | technology<sup>9+</sup> | number[] | 支持的技术类型,每个number值表示所支持技术类型的常量值。 |
| supportedProfiles<sup>7+</sup> | number[] | 支持的技术类型。 | | supportedProfiles | number[] | 支持的技术类型,从API9开始不支持,使用technology替代。 |
## NdefRecord<sup>9+</sup>
NDEF标签Record属性的定义,参考NDEF标签技术规范《NFCForum-TS-NDEF_1.0》的定义细节。
**需要权限**:ohos.permission.NFC_TAG
**系统能力**:SystemCapability.Communication.NFC.Core
| **参数名** | **类型** | **说明** |
| -------- | -------- | -------- |
| tnf | number | NDEF Record的TNF(Type Name Field)。 |
| rtdType| number[] | NDEF Record的RTD(Record Type Definition)类型值,每个number十六进制表示,范围是0x00~0xFF。 |
| id | number[] | NDEF Record的ID,每个number十六进制表示,范围是0x00~0xFF。|
| payload | number[] | NDEF Record的PAYLOAD,每个number十六进制表示,范围是0x00~0xFF。 |
## 技术类型定义
NFC Tag有多种不同的技术类型,定义常量描述不同的技术类型。
**需要权限**:ohos.permission.NFC_TAG
**系统能力**:SystemCapability.Communication.NFC.Core
| **参数名** | **常量值** | **说明** |
| -------- | -------- | -------- |
| NFC_A | 1 | NFC-A(ISO 14443-3A)技术。|
| NFC_B | 2 | NFC-A(ISO 14443-3B)技术。|
| ISO_DEP | 3 | ISO-DEP(ISO 14443-4)技术。|
| NFC_F | 4 | NFC-F(JIS 6319-4)技术。|
| NFC_V | 5 | NFC-V(ISO 15693)技术。|
| NDEF | 6 | NDEF技术。|
| MIFARE_CLASSIC | 8 | Mifare Classic技术。|
| MIFARE_ULTRALIGHT | 9 | Mifare Utralight技术。|
| NDEF_FORMATABLE<sup>9+</sup> | 10 | 可以格式化的NDEF技术。|
## TnfType<sup>9+</sup>
NDEF Record的TNF(Type Name Field)类型值,参考NDEF标签技术规范《NFCForum-TS-NDEF_1.0》的定义细节。
**需要权限**:ohos.permission.NFC_TAG
**系统能力**:SystemCapability.Communication.NFC.Core
| **参数名** | **常量值** | **说明** |
| -------- | -------- | -------- |
| TNF_EMPTY | 0x0 | Empty。|
| TNF_WELL_KNOWN | 0x01 | NFC Forum well-known type [NFC RTD]。|
| TNF_MEDIA | 0x02 | Media-type as defined in RFC 2046 [RFC 2046]。|
| TNF_ABSOLUTE_URI | 0x03 | Absolute URI as defined in RFC 3986 [RFC 3986]。|
| TNF_EXT_APP | 0x04 | NFC Forum external type [NFC RTD]。|
| TNF_UNKNOWN | 0x05 | Unknown。|
| TNF_UNCHANGED | 0x06 | Unchanged (see section 2.3.3)。|
## RtdType<sup>9+</sup>
NDEF Record的RTD(Record Type Definition)类型值,参考NDEF标签技术规范《NFCForum-TS-NDEF_1.0》的定义细节。
**需要权限**:ohos.permission.NFC_TAG
**系统能力**:SystemCapability.Communication.NFC.Core
| **参数名** | **常量值** | **说明** |
| -------- | -------- | -------- |
| RTD_TEXT | 常量 'T' | 文本类型的NDEF Record。|
| RTD_URI | 常量 'U' | URI类型的NDEF Record。|
## NfcForumType<sup>9+</sup>
NFC Forum标准里面Tag类型的定义。
**需要权限**:ohos.permission.NFC_TAG
**系统能力**:SystemCapability.Communication.NFC.Core
| **参数名** | **常量值** | **说明** |
| -------- | -------- | -------- |
| NFC_FORUM_TYPE_1 | 1 | NFC论坛类型1。 |
| NFC_FORUM_TYPE_2 | 2 | NFC论坛类型2。 |
| NFC_FORUM_TYPE_3 | 3 | NFC论坛类型3。 |
| NFC_FORUM_TYPE_4 | 4 | NFC论坛类型4。 |
| MIFARE_CLASSIC | 101 | Mifare Classic类型。 |
## MifareClassicType<sup>9+</sup>
MifareClassic标签类型的定义。
**需要权限**:ohos.permission.NFC_TAG
**系统能力**:SystemCapability.Communication.NFC.Core
| **参数名** | **常量值** | **说明** |
| -------- | -------- | -------- |
| TYPE_UNKNOWN | -1 | 未知Mifare类型。 |
| TYPE_CLASSIC | 0 | Mifare Classic类型。|
| TYPE_PLUS | 1 | Mifare Plus类型。|
| TYPE_PRO | 2 | Mifare Pro类型。 |
## MifareClassicSize<sup>9+</sup>
MifareClassic标签存储大小的定义。
**需要权限**:ohos.permission.NFC_TAG
**系统能力**:SystemCapability.Communication.NFC.Core
| **参数名** | **常量值** | **说明** |
| -------- | -------- | -------- |
| MC_SIZE_MINI | 320 | 每个标签5个扇区,每个扇区4个块。 |
| MC_SIZE_1K | 1024 | 每个标签16个扇区,每个扇区4个块。|
| MC_SIZE_2K | 2048 | 每个标签32个扇区,每个扇区4个块。 |
| MC_SIZE_4K | 4096 | 每个标签40个扇区,每个扇区4个块。|
### MifareUltralightType<sup>9+</sup>
MifareUltralight标签类型的定义。
**需要权限**:ohos.permission.NFC_TAG
**系统能力**:SystemCapability.Communication.NFC.Core
| **参数名** | **常量值** | **说明** |
| -------- | -------- | -------- |
| TYPE_UNKOWN | -1 | 未知的 Mifare 类型。 |
| TYPE_ULTRALIGHT | 1 | Mifare Ultralight类型。|
| TYPE_ULTRALIGHT_C | 2 | Mifare UltralightC 类型。 |
<!--no_check--> <!--no_check-->
\ No newline at end of file
...@@ -33,16 +33,17 @@ getSak(): number ...@@ -33,16 +33,17 @@ getSak(): number
| **类型** | **说明** | | **类型** | **说明** |
| ------------------ | --------------------------| | ------------------ | --------------------------|
| number | NfcA 标签的SAK值。 | | number | NfcA 标签的SAK值,十六进制表示,范围是0x00~0xFF。 |
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
// tagInfo is an Object given by nfc service when tag is dispatched. // see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'nfcA' correctly.
let sak = tag.getNfcATag(taginfo).getSak();
console.log("sak:" +sak); let sak = nfcA.getSak();
console.log("nfcA sak: " + sak);
``` ```
### NfcATag.getAtqa ### NfcATag.getAtqa
...@@ -59,16 +60,16 @@ getAtqa(): number[] ...@@ -59,16 +60,16 @@ getAtqa(): number[]
| **类型** | **说明** | | **类型** | **说明** |
| ------------------ | --------------------------| | ------------------ | --------------------------|
| number[] | NfcA 标签的Atqa值。 | | number[] | NfcA 标签的Atqa值,每个number十六进制表示,范围是0x00~0xFF。 |
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
// tagInfo is an Object given by nfc service when tag is dispatched. // see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'nfcA' correctly.
let atqa = tag.getNfcATag(taginfo).getAtqa(); let atqa = nfcA.getAtqa();
console.log("atqa:" +atqa); console.log("nfcA atqa: " + atqa);
``` ```
## NfcBTag ## NfcBTag
...@@ -93,16 +94,16 @@ getRespAppData(): number[] ...@@ -93,16 +94,16 @@ getRespAppData(): number[]
| **类型** | **说明** | | **类型** | **说明** |
| ------------------ | --------------------------| | ------------------ | --------------------------|
| number[] | NfcB 标签的应用程序数据。 | | number[] | NfcB 标签的应用程序数据,每个number十六进制表示,范围是0x00~0xFF。 |
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
// tagInfo is an Object given by nfc service when tag is dispatched. // see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'nfcB' correctly.
let appData = tag.getNfcBTag(taginfo).getRespAppData(); let respAppData = nfcB.getRespAppData();
console.log("appData:" +appData); console.log("nfcB respAppData: " + respAppData);
``` ```
### NfcBTag.getRespProtocol ### NfcBTag.getRespProtocol
...@@ -119,16 +120,16 @@ getRespProtocol(): number[] ...@@ -119,16 +120,16 @@ getRespProtocol(): number[]
| **类型** | **说明** | | **类型** | **说明** |
| ------------------ | --------------------------| | ------------------ | --------------------------|
| number[] | NfcB 标签的协议信息。| | number[] | NfcB 标签的协议信息,每个number十六进制表示,范围是0x00~0xFF。|
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
// tagInfo is an Object given by nfc service when tag is dispatched. // see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'nfcB' correctly.
let protocol = tag.getNfcBTag(taginfo).getRespProtocol(); let respProtocol = nfcB.getRespProtocol();
console.log("appData:" +protocol); console.log("nfcB respProtocol: " + respProtocol);
``` ```
## NfcFTag ## NfcFTag
...@@ -153,16 +154,16 @@ getSystemCode(): number[] ...@@ -153,16 +154,16 @@ getSystemCode(): number[]
| **类型** | **说明** | | **类型** | **说明** |
| ------------------ | --------------------------| | ------------------ | --------------------------|
| number[] | NfcF 标签的系统代码。| | number[] | NfcF 标签的系统代码,每个number十六进制表示,范围是0x00~0xFF。|
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
// tagInfo is an Object given by nfc service when tag is dispatched. // see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'nfcF' correctly.
let systemCode = tag.getNfcFTag(taginfo).getSystemCode(); let systemCode = nfcF.getSystemCode();
console.log("systemCode:" +systemCode); console.log("nfcF systemCode: " + systemCode);
``` ```
### NfcFTag.getPmm ### NfcFTag.getPmm
...@@ -179,16 +180,16 @@ getPmm(): number[] ...@@ -179,16 +180,16 @@ getPmm(): number[]
| **类型** | **说明** | | **类型** | **说明** |
| ------------------ | --------------------------| | ------------------ | --------------------------|
| number[] | NfcF 标签的PMm信息。| | number[] | NfcF 标签的PMm信息,每个number十六进制表示,范围是0x00~0xFF。|
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
// tagInfo is an Object given by nfc service when tag is dispatched. // see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'nfcF' correctly.
let pmm = tag.getNfcFTag(taginfo).getPmm(); let pmm = nfcF.getPmm();
console.log("pmm:" +pmm); console.log("nfcF pmm: " + pmm);
``` ```
## NfcVTag ## NfcVTag
...@@ -213,16 +214,16 @@ getResponseFlags(): number ...@@ -213,16 +214,16 @@ getResponseFlags(): number
| **类型** | **说明** | | **类型** | **说明** |
| ------------------ | --------------------------| | ------------------ | --------------------------|
| number | NfcV 标签的响应标志。| | number | NfcV 标签的响应标志,十六进制表示,范围是0x00~0xFF。|
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
// tagInfo is an Object given by nfc service when tag is dispatched. // see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'nfcV' correctly.
let flags = tag.getNfcVTag(taginfo).getResponseFlags(); let responseFlags = nfcV.getResponseFlags();
console.log("flags:" +flags); console.log("nfcV responseFlags: " + responseFlags);
``` ```
### NfcvTag.getDsfId ### NfcvTag.getDsfId
...@@ -239,16 +240,16 @@ getDsfId(): number ...@@ -239,16 +240,16 @@ getDsfId(): number
| **类型** | **说明** | | **类型** | **说明** |
| ------------------ | --------------------------| | ------------------ | --------------------------|
| number | NfcV 标签的数据存储格式标识符。| | number | NfcV 标签的数据存储格式标识符,十六进制表示,范围是0x00~0xFF。|
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
// tagInfo is an Object given by nfc service when tag is dispatched. // see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'nfcV' correctly.
let dsfId = tag.getNfcVTag(taginfo).getDsfId(); let dsfId = nfcV.getDsfId();
console.log("dsfId:" +dsfId); console.log("nfcV dsfId: " + dsfId);
``` ```
## IsoDepTag<sup>9+</sup> ## IsoDepTag<sup>9+</sup>
...@@ -261,7 +262,7 @@ TagSession是所有Nfc tag 技术类型的基类, 提供建立连接和发送 ...@@ -261,7 +262,7 @@ TagSession是所有Nfc tag 技术类型的基类, 提供建立连接和发送
### IsoDepTag.getHistoricalBytes<sup>9+</sup> ### IsoDepTag.getHistoricalBytes<sup>9+</sup>
getHistoricalBytes(): string getHistoricalBytes(): number[]
获取标签的历史字节。 获取标签的历史字节。
...@@ -273,21 +274,21 @@ getHistoricalBytes(): string ...@@ -273,21 +274,21 @@ getHistoricalBytes(): string
| **类型** | **说明** | | **类型** | **说明** |
| ------------------ | --------------------------| | ------------------ | --------------------------|
| string | IsoDepTag 标签的历史字节。| | number[] | IsoDepTag 标签的历史字节,每个number十六进制表示,范围是0x00~0xFF。|
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
// tagInfo is an Object given by nfc service when tag is dispatched. // see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'isoDep' correctly.
let historicalBytes = tag.getIsoDepTag(taginfo).getHistoricalBytes(); let historicalBytes = isoDep.getHistoricalBytes();
console.log("historicalBytes:" +historicalBytes); console.log("isoDep historicalBytes: " + historicalBytes);
``` ```
### IsoDepTag.getHiLayerResponse<sup>9+</sup> ### IsoDepTag.getHiLayerResponse<sup>9+</sup>
getHiLayerResponse(): string getHiLayerResponse(): number[]
获取标签的HiLayer响应字节。 获取标签的HiLayer响应字节。
...@@ -299,23 +300,23 @@ getHiLayerResponse(): string ...@@ -299,23 +300,23 @@ getHiLayerResponse(): string
| **类型** | **说明** | | **类型** | **说明** |
| ------------------ | --------------------------| | ------------------ | --------------------------|
| string | IsoDepTag 标签的HiLayer响应字节。| | number[] | IsoDepTag 标签的HiLayer响应字节,每个number十六进制表示,范围是0x00~0xFF。|
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
// tagInfo is an Object given by nfc service when tag is dispatched. // see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'isoDep' correctly.
let hiLayerResponse = tag.getIsoDepTag(taginfo).getHiLayerResponse(); let hiLayerResponse = isoDep.getHiLayerResponse();
console.log("hiLayerResponse:" +hiLayerResponse); console.log("isoDep hiLayerResponse: " + hiLayerResponse);
``` ```
### IsoDepTag.isExtendedApduSupported<sup>9+</sup> ### IsoDepTag.isExtendedApduSupported<sup>9+</sup>
isExtendedApduSupported(): Promise&lt;boolean&gt; isExtendedApduSupported(): Promise&lt;boolean&gt;
检查是否支持外部apdu长度,使用promise方式作为异步方法。 检查是否支持扩展的APDU,使用promise方式作为异步方法。
**需要权限**:ohos.permission.NFC_TAG **需要权限**:ohos.permission.NFC_TAG
...@@ -332,17 +333,20 @@ isExtendedApduSupported(): Promise&lt;boolean&gt; ...@@ -332,17 +333,20 @@ isExtendedApduSupported(): Promise&lt;boolean&gt;
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
// tagInfo is an Object given by nfc service when tag is dispatched. // see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'isoDep' correctly.
tag.getIsoDepTag(taginfo).isExtendedApduSupported().then(function (has) { isoDep.isExtendedApduSupported()
console.log('has: ' + has) .then((data) => {
}) console.log("isoDep isExtendedApduSupported data: " + data);
}).catch((err)=> {
console.log("isoDep isExtendedApduSupported err: " + err);
});
``` ```
### IsoDepTag.isExtendedApduSupported<sup>9+</sup> ### IsoDepTag.isExtendedApduSupported<sup>9+</sup>
isExtendedApduSupported(callback: AsyncCallback\<boolean>): void isExtendedApduSupported(callback: AsyncCallback\<boolean>): void
检查是否支持外部apdu长度,使用callback方式作为异步方法。 检查是否支持扩展的APDU,使用callback方式作为异步方法。
**需要权限**:ohos.permission.NFC_TAG **需要权限**:ohos.permission.NFC_TAG
...@@ -357,24 +361,27 @@ isExtendedApduSupported(callback: AsyncCallback\<boolean>): void ...@@ -357,24 +361,27 @@ isExtendedApduSupported(callback: AsyncCallback\<boolean>): void
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
// tagInfo is an Object given by nfc service when tag is dispatched. // see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'isoDep' correctly.
tag.getIsoDepTag(taginfo).isExtendedApduSupported(function (error, has) { isoDep.isExtendedApduSupported((err, data)=> {
console.log(JSON.stringify(error)) if (err) {
console.log('has: ' + has) console.log("isoDep isExtendedApduSupported err: " + err);
}) } else {
console.log("isoDep isExtendedApduSupported data: " + data);
}
});
``` ```
## NdefTag<sup>9+</sup> ## NdefTag<sup>9+</sup>
提供对已格式化为NDEF的NFC标签的数据和操作的访问,继承自TagSession。 提供对已格式化为NDEF的NFC标签的数据和操作的访问,继承自TagSession。
TagSession是所有Nfc tag 技术类型的基类, 提供建立连接和发送数据等共同接口。具体请参见[TagSession](js-apis-tagSession.md) TagSession是所有NFC Tag技术类型的基类, 提供建立连接和发送数据等共同接口。具体请参见[TagSession](js-apis-tagSession.md)
以下是NdefTag的独有接口。 以下是NdefTag的独有接口。
### NdefTag.createNdefMessage<sup>9+</sup> ### NdefTag.createNdefMessage<sup>9+</sup>
createNdefMessage(data: string): [NdefMessage](#ndefmessage9) createNdefMessage(data: number[]): [NdefMessage](#ndefmessage9)
使用原始字节创建ndef消息。 使用原始字节创建ndef消息。
...@@ -386,28 +393,30 @@ createNdefMessage(data: string): [NdefMessage](#ndefmessage9) ...@@ -386,28 +393,30 @@ createNdefMessage(data: string): [NdefMessage](#ndefmessage9)
| **参数名** | **类型** | **必填** | **说明** | | **参数名** | **类型** | **必填** | **说明** |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| data | string | 是 | 字符串类型的原始字节 | | data | number[] | 是 | 原始字节,每个number十六进制表示,范围是0x00~0xFF |
**返回值:** **返回值:**
| **类型** | **说明** | | **类型** | **说明** |
| ------------------ | --------------------------| | ------------------ | --------------------------|
| [NdefMessage](#ndefmessage9) | Ndef消息 | | [NdefMessage](#ndefmessage9) | NDEF标签的Message,详见NDEF技术规范《NFCForum-TS-NDEF_1.0》。 |
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
// tagInfo is an Object given by nfc service when tag is dispatched. // see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'ndef' correctly.
let NdefMessage = tag.NdefTag(taginfo).createNdefMessage(data); let rawData = [0x00, 0xa4, 0x04, ......]; // change the raw data bytes tobe correct.
let ndefMessage = ndef.createNdefMessage(rawData);
console.log("ndef ndefMessage: " + ndefMessage);
``` ```
## NdefMessage<sup>9+</sup> ## NdefMessage<sup>9+</sup>
### NdefMessage.getNdefRecords<sup>9+</sup> ### NdefMessage.getNdefRecords<sup>9+</sup>
getNdefRecords(): [NdefRecord](#ndefrecord9)[ ] getNdefRecords(): [NdefRecord](js-apis-nfcTag.md#ndefrecord9)[ ]
获取ndef消息的所有记录。 获取ndef消息的所有记录。
...@@ -419,38 +428,23 @@ getNdefRecords(): [NdefRecord](#ndefrecord9)[ ] ...@@ -419,38 +428,23 @@ getNdefRecords(): [NdefRecord](#ndefrecord9)[ ]
| **类型** | **说明** | | **类型** | **说明** |
| ------------------ | --------------------------| | ------------------ | --------------------------|
| [NdefRecord](#ndefrecord9)[ ] | Ndef消息所包含的所有记录。 | | [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';
// tagInfo is an Object given by nfc service when tag is dispatched. // see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'ndef' correctly.
let NdefRecord = tag.NdefTag(taginfo).getNdefRecords(); let ndefRecords = ndef.getNdefRecords();
console.log("ndef ndefRecords number: " + ndefRecords.length);
``` ```
## NdefRecord<sup>9+</sup>
| **参数名** | **类型** | **说明** |
| -------- | -------- | -------- |
| tnf | number | 标签的uid。 |
| [rtdType](#rtdtype9) | string | 支持的技术类型。 |
| id | string | 标签的额外信息。 |
| payload | string | 标签的RF discovery id。 |
## RtdType<sup>9+</sup>
| **参数名** | **类型** | **说明** |
| -------- | -------- | -------- |
| RTD_TEXT | 'T' | 记录描述文本信息。|
| RTD_URI | 'U' | 存储网络地址,邮件或者电话号码。|
### NdefTag.createNdefMessage<sup>9+</sup> ### NdefTag.createNdefMessage<sup>9+</sup>
createNdefMessage(ndefRecords: NdefRecord[]): [NdefMessage](#ndefmessage9) createNdefMessage(ndefRecords: NdefRecord[]): [NdefMessage](#ndefmessage9)
使用记录列表创建ndef消息。 使用记录列表创建NDEF消息。
**需要权限**:ohos.permission.NFC_TAG **需要权限**:ohos.permission.NFC_TAG
...@@ -459,21 +453,32 @@ createNdefMessage(ndefRecords: NdefRecord[]): [NdefMessage](#ndefmessage9) ...@@ -459,21 +453,32 @@ createNdefMessage(ndefRecords: NdefRecord[]): [NdefMessage](#ndefmessage9)
**参数:** **参数:**
| **参数名** | **类型** | **必填** | **说明** | | **参数名** | **类型** | **必填** | **说明** |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| ndefRecords | [NdefRecord](#ndefrecord9)[] | 是 | NdefRecord记录列表。 | | ndefRecords | [NdefRecord](js-apis-nfcTag.md#ndefrecord9)[] | 是 | NDEF标签的Record列表,详见NDEF技术规范《NFCForum-TS-NDEF_1.0》。 |
**返回值:** **返回值:**
| **类型** | **说明** | | **类型** | **说明** |
| ------------------ | --------------------------| | ------------------ | --------------------------|
| [NdefMessage](#ndefmessage9) | Ndef消息。| | [NdefMessage](#ndefmessage9) | NDEF标签的Message,详见NDEF技术规范《NFCForum-TS-NDEF_1.0》。|
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
// tagInfo is an Object given by nfc service when tag is dispatched. // see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'ndef' correctly.
let NdefMessage = tag.NdefTag(taginfo).createNdefMessage(ndefRecords); let ndefRecords = [
// record format: tnf, rtdType, id, payload
// 1st record:
{tnf: 0x01, rtdType: [0x54], id: [0x01, 0x02, ...], payload: [0x00, 0xa4, 0x04, ...]},
// 2nd record:
{tnf: 0x02, rtdType: [0x55], id: [0x03, 0x04, ...], payload: [0x00, 0xa4, 0x04, ...]},
// other record if has one ...
];
let ndefMessage = ndef.createNdefMessage(ndefRecords);
console.log("ndef ndefMessage: " + ndefMessage);
``` ```
### NdefTag.getNdefTagType<sup>9+</sup> ### NdefTag.getNdefTagType<sup>9+</sup>
...@@ -490,22 +495,23 @@ getNdefTagType(): NfcForumType ...@@ -490,22 +495,23 @@ getNdefTagType(): NfcForumType
| **类型** | **说明** | | **类型** | **说明** |
| ------------------ | --------------------------| | ------------------ | --------------------------|
| [NfcForumType](#nfcforumtype9) | Ndef标签类型。| | [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';
// tagInfo is an Object given by nfc service when tag is dispatched. // see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'ndef' correctly.
let NfcForumType = tag.NdefTag(taginfo).getNdefTagType(); let ndefTagType = ndef.getNdefTagType();
console.log("ndef ndefTagType: " + ndefTagType);
``` ```
### NdefTag.getNdefMessage<sup>9+</sup> ### NdefTag.getNdefMessage<sup>9+</sup>
getNdefMessage(): NdefMessage getNdefMessage(): NdefMessage
获取发现标签时,从ndef标签读取的ndef消息 获取发现NDEF标签时,从标签读取的Message
**需要权限**:ohos.permission.NFC_TAG **需要权限**:ohos.permission.NFC_TAG
...@@ -515,22 +521,23 @@ getNdefMessage(): NdefMessage ...@@ -515,22 +521,23 @@ getNdefMessage(): NdefMessage
| **类型** | **说明** | | **类型** | **说明** |
| ------------------ | --------------------------| | ------------------ | --------------------------|
| [NdefMessage](#ndefmessage9) | Ndef消息。| | [NdefMessage](#ndefmessage9) | NDEF标签的Message,详见NDEF技术规范《NFCForum-TS-NDEF_1.0》。|
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
// tagInfo is an Object given by nfc service when tag is dispatched. // see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'ndef' correctly.
let NdefMessage = tag.NdefTag(taginfo).getNdefMessage(); let ndefMessage = ndef.getNdefMessage();
console.log("ndef ndefMessage: " + ndefMessage);
``` ```
### NdefTag.isNdefWritable<sup>9+</sup> ### NdefTag.isNdefWritable<sup>9+</sup>
isNdefWritable(): Promise&lt;boolean&gt; isNdefWritable(): Promise&lt;boolean&gt;
检查ndef标签是否可写,使用promise方式作为异步方法。 检查NDEF标签是否可写,使用promise方式作为异步方法。
**需要权限**:ohos.permission.NFC_TAG **需要权限**:ohos.permission.NFC_TAG
...@@ -547,10 +554,13 @@ isNdefWritable(): Promise&lt;boolean&gt; ...@@ -547,10 +554,13 @@ isNdefWritable(): Promise&lt;boolean&gt;
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
// tagInfo is an Object given by nfc service when tag is dispatched. // see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'ndef' correctly.
tag.NdefTag(taginfo).isNdefWritable().then(function (has) { ndef.isNdefWritable()
console.log(JSON.stringify(has)) .then((data) => {
}) console.log("ndef isNdefWritable data: " + data);
}).catch((err)=> {
console.log("ndef isNdefWritable err: " + err);
});
``` ```
### NdefTag.isNdefWritable<sup>9+</sup> ### NdefTag.isNdefWritable<sup>9+</sup>
...@@ -567,18 +577,21 @@ isNdefWritable(callback: AsyncCallback&lt;boolean&gt;): void; ...@@ -567,18 +577,21 @@ isNdefWritable(callback: AsyncCallback&lt;boolean&gt;): void;
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | -------------------------------------- | | -------- | ----------------------- | ---- | -------------------------------------- |
| callback | AsyncCallback\<boolean> | 是 | 回调函数,ndef标签可写,返回true。 | | callback | AsyncCallback\<boolean> | 是 | 回调函数,NDEF标签可写,返回true。 |
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
// tagInfo is an Object given by nfc service when tag is dispatched. // see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'ndef' correctly.
tag.NdefTag(taginfo).isNdefWritable(function (error, has) { ndef.isNdefWritable((err, data)=> {
console.log(JSON.stringify(error)) if (err) {
console.log('has: ' + has) console.log("ndef isNdefWritable err: " + err);
}) } else {
console.log("ndef isNdefWritable data: " + data);
}
});
``` ```
### NdefTag.readNdef<sup>9+</sup> ### NdefTag.readNdef<sup>9+</sup>
...@@ -595,17 +608,20 @@ readNdef(): Promise\<NdefMessage> ...@@ -595,17 +608,20 @@ readNdef(): Promise\<NdefMessage>
| **类型** | **说明** | | **类型** | **说明** |
| ------------------ | --------------------------| | ------------------ | --------------------------|
| Promise\<[NdefMessage](#ndefmessage9)> | 以Promise形式返回从标签中读取到的NdefMessage信息。| | Promise\<[NdefMessage](#ndefmessage9)> | 以Promise形式返回从NDEF标签中读取到的Message信息。|
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
// tagInfo is an Object given by nfc service when tag is dispatched. // see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'ndef' correctly.
tag.NdefTag(taginfo).readNdef().then(function (ndefMessage) { ndef.readNdef()
console.log(JSON.stringify(ndefMessage)) .then((data) => {
}) console.log("ndef readNdef data: " + data);
}).catch((err)=> {
console.log("ndef readNdef err: " + err);
});
``` ```
### NdefTag.readNdef<sup>9+</sup> ### NdefTag.readNdef<sup>9+</sup>
...@@ -629,11 +645,14 @@ readNdef(callback: AsyncCallback\<[NdefMessage](#ndefmessage9)>): void ...@@ -629,11 +645,14 @@ readNdef(callback: AsyncCallback\<[NdefMessage](#ndefmessage9)>): void
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
// tagInfo is an Object given by nfc service when tag is dispatched. // see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'ndef' correctly.
tag.NdefTag(taginfo).readNdef(function (error, ndefMessage) { ndef.readNdef((err, data)=> {
console.log(JSON.stringify(error)) if (err) {
console.log('ndefMessage: ' + ndefMessage) console.log("ndef readNdef err: " + err);
}) } else {
console.log("ndef readNdef data: " + data);
}
});
``` ```
### NdefTag.writeNdef<sup>9+</sup> ### NdefTag.writeNdef<sup>9+</sup>
...@@ -663,10 +682,15 @@ writeNdef(msg: NdefMessage): Promise\<number>; ...@@ -663,10 +682,15 @@ writeNdef(msg: NdefMessage): Promise\<number>;
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
// tagInfo is an Object given by nfc service when tag is dispatched. // see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'ndef' correctly.
NdefTag.writeNdef(msg).then(function (netHandle) { let ndefMessage = ndef.createNdefMessage([0x01, 0x02, ...]); // change the raw data to be correct.
console.log(JSON.stringify(netHandle))
}) ndef.writeNdef(ndefMessage)
.then((data) => {
console.log("ndef writeNdef data: " + data);
}).catch((err)=> {
console.log("ndef writeNdef err: " + err);
});
``` ```
### NdefTag.writeNdef<sup>9+</sup> ### NdefTag.writeNdef<sup>9+</sup>
...@@ -691,11 +715,15 @@ writeNdef(msg: NdefMessage, callback: AsyncCallback\<number>): void ...@@ -691,11 +715,15 @@ writeNdef(msg: NdefMessage, callback: AsyncCallback\<number>): void
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
// tagInfo is an Object given by nfc service when tag is dispatched. // see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'ndef' correctly.
tag.NdefTag(taginfo).write(msg, function (error, has) { let ndefMessage = ndef.createNdefMessage([0x01, 0x02, ...]); // change the raw data to be correct.
console.log(JSON.stringify(error)) ndef.writeNdef(ndefMessage, (err, data)=> {
console.log('has: ' + has) if (err) {
}) console.log("ndef writeNdef err: " + err);
} else {
console.log("ndef writeNdef data: " + data);
}
});
``` ```
### NdefTag.canSetReadOnly<sup>9+</sup> ### NdefTag.canSetReadOnly<sup>9+</sup>
...@@ -712,17 +740,20 @@ canSetReadOnly(): Promise\<boolean> ...@@ -712,17 +740,20 @@ canSetReadOnly(): Promise\<boolean>
| **类型** | **说明** | | **类型** | **说明** |
| ------------------ | --------------------------| | ------------------ | --------------------------|
| Promise&lt;boolean&gt; | true: 标签可设置为只读, false: 标签不可设置为只读。 | | Promise&lt;boolean&gt; | true: NDEF标签可设置为只读, false: NDEF标签不可设置为只读。 |
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
// tagInfo is an Object given by nfc service when tag is dispatched. // see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'ndef' correctly.
tag.NdefTag(taginfo).canSetReadOnly().then(function (has) { ndef.canSetReadOnly()
console.log(JSON.stringify(has)) .then((data) => {
}) console.log("ndef canSetReadOnly data: " + data);
}).catch((err)=> {
console.log("ndef canSetReadOnly err: " + err);
});
``` ```
### NdefTag.canSetReadOnly<sup>9+</sup> ### NdefTag.canSetReadOnly<sup>9+</sup>
...@@ -739,18 +770,21 @@ canSetReadOnly(callback: AsyncCallback&lt;boolean&gt;): void; ...@@ -739,18 +770,21 @@ canSetReadOnly(callback: AsyncCallback&lt;boolean&gt;): void;
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | -------------------------------------- | | -------- | ----------------------- | ---- | -------------------------------------- |
| callback | AsyncCallback\<boolean> | 是 | 回调函数,ndef标签可设置为只读,返回true。 | | callback | AsyncCallback\<boolean> | 是 | 回调函数,NDEF标签可设置为只读,返回true。 |
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
// tagInfo is an Object given by nfc service when tag is dispatched. // see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'ndef' correctly.
tag.NdefTag(taginfo).canSetReadOnly(function (error, has) { ndef.canSetReadOnly((err, data)=> {
console.log(JSON.stringify(error)) if (err) {
console.log('has: ' + has) console.log("ndef canSetReadOnly err: " + err);
}) } else {
console.log("ndef canSetReadOnly data: " + data);
}
});
``` ```
### NdefTag.setReadOnly<sup>9+</sup> ### NdefTag.setReadOnly<sup>9+</sup>
...@@ -774,10 +808,13 @@ setReadOnly(): Promise\<number> ...@@ -774,10 +808,13 @@ setReadOnly(): Promise\<number>
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
// tagInfo is an Object given by nfc service when tag is dispatched. // see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'ndef' correctly.
tag.NdefTag(taginfo).setReadOnly().then(function (errcode) { ndef.setReadOnly()
console.log(JSON.stringify(errcode)) .then((data) => {
}) console.log("ndef setReadOnly data: " + data);
}).catch((err)=> {
console.log("ndef setReadOnly err: " + err);
});
``` ```
### NdefTag.setReadOnly<sup>9+</sup> ### NdefTag.setReadOnly<sup>9+</sup>
...@@ -801,16 +838,19 @@ setReadOnly(callback: AsyncCallback<number>): void ...@@ -801,16 +838,19 @@ setReadOnly(callback: AsyncCallback<number>): void
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
// tagInfo is an Object given by nfc service when tag is dispatched. // see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'ndef' correctly.
tag.NdefTag(taginfo).setReadOnly(function (error, errcode) { ndef.setReadOnly((err, data)=> {
console.log(JSON.stringify(error)) if (err) {
console.log('has: ' + errcode) console.log("ndef setReadOnly err: " + err);
}) } else {
console.log("ndef setReadOnly data: " + data);
}
});
``` ```
### NdefTag.getNdefTagTypeString<sup>9+</sup> ### NdefTag.getNdefTagTypeString<sup>9+</sup>
getNdefTagTypeString(type: [NfcForumType](#nfcforumtype9)): string getNdefTagTypeString(type: [NfcForumType](js-apis-nfcTag.md#nfcforumtype9)): string
将Nfc论坛类型转换为Nfc论坛中定义的字节数组。 将Nfc论坛类型转换为Nfc论坛中定义的字节数组。
...@@ -822,36 +862,25 @@ getNdefTagTypeString(type: [NfcForumType](#nfcforumtype9)): string ...@@ -822,36 +862,25 @@ getNdefTagTypeString(type: [NfcForumType](#nfcforumtype9)): string
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | -------------------------------------- | | -------- | ----------------------- | ---- | -------------------------------------- |
| type | [NfcForumType](#nfcforumtype9) | 是 | NfcForum论坛类型。 | | type | [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';
// tagInfo is an Object given by nfc service when tag is dispatched. // see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'ndef' correctly.
let ndefTypeString= tag.NdefTag(taginfo).getNdefTagTypeString(type); let ndefTypeString = ndef.getNdefTagTypeString(tag.NFC_FORUM_TYPE_1);
console.log("ndef ndefTypeString: " + ndefTypeString);
``` ```
## NfcForumType<sup>9+</sup> ## MifareClassicTag<sup>9+</sup>
**系统能力**:SystemCapability.Communication.NFC.Core
| **参数名** | **类型** | **说明** |
| -------- | -------- | -------- |
| NFC_FORUM_TYPE_1 | 1 | NFC论坛类型1。 |
| NFC_FORUM_TYPE_2 | 2 | NFC论坛类型2。 |
| NFC_FORUM_TYPE_3 | 3 | NFC论坛类型3。 |
| NFC_FORUM_TYPE_4 | 4 | NFC论坛类型4。 |
| MIFARE_CLASSIC | 101 | Mifare Classic类型。 |
## MifareClassicTag <sup>9+</sup>
MifareClassicTag提供对MIFARE经典属性和I/O操作的访问,继承自TagSession。 MifareClassicTag提供对MIFARE经典属性和I/O操作的访问,继承自TagSession。
...@@ -888,10 +917,15 @@ authenticateSector(sectorIndex: number, key: number[], isKeyA: boolean): Promise ...@@ -888,10 +917,15 @@ authenticateSector(sectorIndex: number, key: number[], isKeyA: boolean): Promise
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
// tagInfo is an Object given by nfc service when tag is dispatched. // see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'mifareClassic' correctly.
tag.MifareClassicTag(taginfo).authenticateSector(sectorIndex, key).then(function (isKeyA) { let sectorIndex = 1; // change it to be correct index.
console.log(JSON.stringify(isKeyA)) let key = [0x04, 0x05, ....]; // change it to be correct key.
}) mifareClassic.authenticateSector(sectorIndex, key, true);
.then((data) => {
console.log("mifareClassic authenticateSector data: " + data);
}).catch((err)=> {
console.log("mifareClassic authenticateSector err: " + err);
});
``` ```
### MifareClassicTag.authenticateSector<sup>9+</sup> ### MifareClassicTag.authenticateSector<sup>9+</sup>
...@@ -918,16 +952,21 @@ authenticateSector(sectorIndex: number, key: number[], isKeyA: boolean, callback ...@@ -918,16 +952,21 @@ authenticateSector(sectorIndex: number, key: number[], isKeyA: boolean, callback
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
// tagInfo is an Object given by nfc service when tag is dispatched. // see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'mifareClassic' correctly.
tag.MifareClassicTag(taginfo).authenticateSector(sectorIndex, key, function (error, has) { let sectorIndex = 1; // change it to be correct index.
console.log(JSON.stringify(error)) let key = [0x04, 0x05, ....]; // change it to be correct key.
console.log('has: ' + has) mifareClassic.authenticateSector(sectorIndex, key, true, (err, data)=> {
}) if (err) {
console.log("mifareClassic authenticateSector err: " + err);
} else {
console.log("mifareClassic authenticateSector data: " + data);
}
});
``` ```
### MifareClassicTag.readSingleBlock<sup>9+</sup> ### MifareClassicTag.readSingleBlock<sup>9+</sup>
readSingleBlock(blockIndex: number): Promise\<string> readSingleBlock(blockIndex: number): Promise\<number[]>
读取标签中一个块存储的内容,一个块大小为16字节。使用promise方式作为异步方法。 读取标签中一个块存储的内容,一个块大小为16字节。使用promise方式作为异步方法。
...@@ -945,23 +984,27 @@ readSingleBlock(blockIndex: number): Promise\<string> ...@@ -945,23 +984,27 @@ readSingleBlock(blockIndex: number): Promise\<string>
| **类型** | **说明** | | **类型** | **说明** |
| ------------------ | --------------------------| | ------------------ | --------------------------|
| Promise\<string> | 读取的块数据。 | | Promise\<number[]> | 读取的块数据。 |
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
let data = "xxx"; // see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'mifareClassic' correctly.
// tagInfo is an Object given by nfc service when tag is dispatched. let blockIndex = 1; // change it to be correct index.
tag.MifareClassicTag(taginfo).readSingleBlock(blockIndex).then(function (data){ mifareClassic.readSingleBlock(blockIndex, (err, data)=> {
console.log('data: ' + data) if (err) {
}) console.log("mifareClassic readSingleBlock err: " + err);
} else {
console.log("mifareClassic readSingleBlock data: " + data);
}
});
``` ```
### MifareClassicTag.readSingleBlock<sup>9+</sup> ### MifareClassicTag.readSingleBlock<sup>9+</sup>
readSingleBlock(blockIndex: number, callback: AsyncCallback\<string>): void readSingleBlock(blockIndex: number, callback: AsyncCallback\<number[]>): void
读取标签中一个块存储的内容,一个块大小为16字节。使用callback方式作为异步方法。 读取标签中一个块存储的内容,一个块大小为16字节。使用callback方式作为异步方法。
...@@ -974,24 +1017,27 @@ readSingleBlock(blockIndex: number, callback: AsyncCallback\<string>): void ...@@ -974,24 +1017,27 @@ readSingleBlock(blockIndex: number, callback: AsyncCallback\<string>): void
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | -------------------------------------- | | -------- | ----------------------- | ---- | -------------------------------------- |
| blockIndex | number | 是 | 要读取的块索引 | | blockIndex | number | 是 | 要读取的块索引 |
| callback | AsyncCallback\<string> | 是 | 回调函数。 | | callback | AsyncCallback\<number[]> | 是 | 回调函数。 |
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
let data = "xxx"; // see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'mifareClassic' correctly.
// tagInfo is an Object given by nfc service when tag is dispatched. let blockIndex = 1; // change it to be correct index.
tag.MifareClassicTag(taginfo).readSingleBlock(blockIndex, function (error, data) { mifareClassic.readSingleBlock(blockIndex, (err, data)=> {
console.log(JSON.stringify(error)) if (err) {
console.log('data: ' + data) console.log("mifareClassic readSingleBlock err: " + err);
}) } else {
console.log("mifareClassic readSingleBlock data: " + data);
}
});
``` ```
### MifareClassicTag.writeSingleBlock<sup>9+</sup> ### MifareClassicTag.writeSingleBlock<sup>9+</sup>
writeSingleBlock(blockIndex: number, data: string): Promise\<number> writeSingleBlock(blockIndex: number, data: number[]): Promise\<number>
向标签中一个块存储写入内容,一个块大小为16字节。使用promise方式作为异步方法。 向标签中一个块存储写入内容,一个块大小为16字节。使用promise方式作为异步方法。
...@@ -1004,7 +1050,7 @@ writeSingleBlock(blockIndex: number, data: string): Promise\<number> ...@@ -1004,7 +1050,7 @@ writeSingleBlock(blockIndex: number, data: string): Promise\<number>
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | -------------------------------------- | | -------- | ----------------------- | ---- | -------------------------------------- |
| blockIndex | number | 是 | 要写入的块索引。 | | blockIndex | number | 是 | 要写入的块索引。 |
| data | string | 是 | 要写入的数据。 | | data | number[] | 是 | 要写入的数据。 |
**返回值:** **返回值:**
...@@ -1017,16 +1063,21 @@ writeSingleBlock(blockIndex: number, data: string): Promise\<number> ...@@ -1017,16 +1063,21 @@ writeSingleBlock(blockIndex: number, data: string): Promise\<number>
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
let data = "xxx"; // see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'mifareClassic' correctly.
// tagInfo is an Object given by nfc service when tag is dispatched. let blockIndex = 1; // change it to be correct index.
tag.MifareClassicTag(taginfo).writeSingleBlock(blockIndex, data).then(function (errcode){ let rawData = [0x0a, 0x14, ...]; // change it to be correct data.
console.log(JSON.stringify(errcode)) mifareClassic.writeSingleBlock(blockIndex, rawData, (err, data)=> {
}) if (err) {
console.log("mifareClassic writeSingleBlock err: " + err);
} else {
console.log("mifareClassic writeSingleBlock data: " + data);
}
});
``` ```
### MifareClassicTag.writeSingleBlock<sup>9+</sup> ### MifareClassicTag.writeSingleBlock<sup>9+</sup>
writeSingleBlock(blockIndex: number, data: string, callback: AsyncCallback\<number>): void writeSingleBlock(blockIndex: number, data: number[], callback: AsyncCallback\<number>): void
向标签中一个块存储写入内容,一个块大小为16字节。使用callback方式作为异步方法。 向标签中一个块存储写入内容,一个块大小为16字节。使用callback方式作为异步方法。
...@@ -1039,7 +1090,7 @@ writeSingleBlock(blockIndex: number, data: string, callback: AsyncCallback\<numb ...@@ -1039,7 +1090,7 @@ writeSingleBlock(blockIndex: number, data: string, callback: AsyncCallback\<numb
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | -------------------------------------- | | -------- | ----------------------- | ---- | -------------------------------------- |
| blockIndex | number | 是 | 要写入的块索引 | | blockIndex | number | 是 | 要写入的块索引 |
| data | string | 是 | 要写入的数据 | | data | number[] | 是 | 要写入的数据 |
| callback | AsyncCallback\<number> | 是 | 回调函数。 | | callback | AsyncCallback\<number> | 是 | 回调函数。 |
**示例:** **示例:**
...@@ -1047,12 +1098,16 @@ writeSingleBlock(blockIndex: number, data: string, callback: AsyncCallback\<numb ...@@ -1047,12 +1098,16 @@ writeSingleBlock(blockIndex: number, data: string, callback: AsyncCallback\<numb
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
let data = "xxx"; // see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'mifareClassic' correctly.
// tagInfo is an Object given by nfc service when tag is dispatched. let blockIndex = 1; // change it to be correct index.
tag.MifareClassicTag(taginfo).writeSingleBlock(blockIndex, data, function (error, errcode) { let rawData = [0x0a, 0x14, ...]; // change it to be correct data.
console.log(JSON.stringify(error)) mifareClassic.writeSingleBlock(blockIndex, rawData, (err, data)=> {
console.log(JSON.stringify(errcode)) if (err) {
}) console.log("mifareClassic writeSingleBlock err: " + err);
} else {
console.log("mifareClassic writeSingleBlock data: " + data);
}
});
``` ```
### MifareClassicTag.incrementBlock<sup>9+</sup> ### MifareClassicTag.incrementBlock<sup>9+</sup>
...@@ -1083,10 +1138,16 @@ incrementBlock(blockIndex: number, value: number): Promise\<number> ...@@ -1083,10 +1138,16 @@ incrementBlock(blockIndex: number, value: number): Promise\<number>
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
// tagInfo is an Object given by nfc service when tag is dispatched. // see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'mifareClassic' correctly.
tag.MifareClassicTag(taginfo).incrementBlock(blockIndex, value).then(function (errcode){ let blockIndex = 1; // change it to be correct index.
console.log(JSON.stringify(errcode)) let value = 0x20; // change it to be correct data.
}) mifareClassic.incrementBlock(blockIndex, value, (err, data)=> {
if (err) {
console.log("mifareClassic incrementBlock err: " + err);
} else {
console.log("mifareClassic incrementBlock data: " + data);
}
});
``` ```
### MifareClassicTag.incrementBlock<sup>9+</sup> ### MifareClassicTag.incrementBlock<sup>9+</sup>
...@@ -1112,11 +1173,16 @@ incrementBlock(blockIndex: number, value: number, callback: AsyncCallback\<numbe ...@@ -1112,11 +1173,16 @@ incrementBlock(blockIndex: number, value: number, callback: AsyncCallback\<numbe
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
// tagInfo is an Object given by nfc service when tag is dispatched. // see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'mifareClassic' correctly.
tag.MifareClassicTag(taginfo).incrementBlock(blockIndex, value, function (error, errcode) { let blockIndex = 1; // change it to be correct index.
console.log(JSON.stringify(error)) let value = 0x20; // change it to be correct data.
console.log(JSON.stringify(errcode)) mifareClassic.incrementBlock(blockIndex, value, (err, data)=> {
}) if (err) {
console.log("mifareClassic incrementBlock err: " + err);
} else {
console.log("mifareClassic incrementBlock data: " + data);
}
});
``` ```
### MifareClassicTag.decrementBlock<sup>9+</sup> ### MifareClassicTag.decrementBlock<sup>9+</sup>
...@@ -1147,10 +1213,16 @@ decrementBlock(blockIndex: number, value: number): Promise\<number> ...@@ -1147,10 +1213,16 @@ decrementBlock(blockIndex: number, value: number): Promise\<number>
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
// tagInfo is an Object given by nfc service when tag is dispatched. // see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'mifareClassic' correctly.
tag.MifareClassicTag(taginfo).decrementBlock(blockIndex, value).then(function (errcode){ let blockIndex = 1; // change it to be correct index.
console.log(JSON.stringify(errcode)) let value = 0x20; // change it to be correct data.
}) mifareClassic.decrementBlock(blockIndex, value, (err, data)=> {
if (err) {
console.log("mifareClassic decrementBlock err: " + err);
} else {
console.log("mifareClassic decrementBlock data: " + data);
}
});
``` ```
### MifareClassicTag.decrementBlock<sup>9+</sup> ### MifareClassicTag.decrementBlock<sup>9+</sup>
...@@ -1176,11 +1248,16 @@ decrementBlock(blockIndex: number, value: number, callback: AsyncCallback\<numbe ...@@ -1176,11 +1248,16 @@ decrementBlock(blockIndex: number, value: number, callback: AsyncCallback\<numbe
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
// tagInfo is an Object given by nfc service when tag is dispatched. // see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'mifareClassic' correctly.
tag.MifareClassicTag(taginfo).decrementBlock(blockIndex, value, function (error, errcode) { let blockIndex = 1; // change it to be correct index.
console.log(JSON.stringify(error)) let value = 0x20; // change it to be correct data.
console.log(JSON.stringify(errcode)) mifareClassic.decrementBlock(blockIndex, value, (err, data)=> {
}) if (err) {
console.log("mifareClassic decrementBlock err: " + err);
} else {
console.log("mifareClassic decrementBlock data: " + data);
}
});
``` ```
### MifareClassicTag.transferToBlock<sup>9+</sup> ### MifareClassicTag.transferToBlock<sup>9+</sup>
...@@ -1211,13 +1288,18 @@ transferToBlock(blockIndex: number): Promise\<number> ...@@ -1211,13 +1288,18 @@ transferToBlock(blockIndex: number): Promise\<number>
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
// tagInfo is an Object given by nfc service when tag is dispatched. // see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'mifareClassic' correctly.
tag.MifareClassicTag(taginfo).transferToBlock(blockIndex).then(function (errcode){ let blockIndex = 1; // change it to be correct index.
console.log(JSON.stringify(errcode)) mifareClassic.transferToBlock(blockIndex, (err, data)=> {
}) if (err) {
console.log("mifareClassic transferToBlock err: " + err);
} else {
console.log("mifareClassic transferToBlock data: " + data);
}
});
``` ```
### MifareClassicTag.transferToBlock ### MifareClassicTag.transferToBlock<sup>9+</sup>
transferToBlock(blockIndex: number, callback: AsyncCallback\<number>): void transferToBlock(blockIndex: number, callback: AsyncCallback\<number>): void
...@@ -1239,11 +1321,15 @@ transferToBlock(blockIndex: number, callback: AsyncCallback\<number>): void ...@@ -1239,11 +1321,15 @@ transferToBlock(blockIndex: number, callback: AsyncCallback\<number>): void
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
// tagInfo is an Object given by nfc service when tag is dispatched. // see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'mifareClassic' correctly.
tag.MifareClassicTag(taginfo).transferToBlock(blockIndex, function (error, errcode) { let blockIndex = 1; // change it to be correct index.
console.log(JSON.stringify(error)) mifareClassic.transferToBlock(blockIndex, (err, data)=> {
console.log(JSON.stringify(errcode)) if (err) {
}) console.log("mifareClassic transferToBlock err: " + err);
} else {
console.log("mifareClassic transferToBlock data: " + data);
}
});
``` ```
### MifareClassicTag.restoreFromBlock<sup>9+</sup> ### MifareClassicTag.restoreFromBlock<sup>9+</sup>
...@@ -1274,10 +1360,14 @@ restoreFromBlock(blockIndex: number): Promise\<number> ...@@ -1274,10 +1360,14 @@ restoreFromBlock(blockIndex: number): Promise\<number>
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
// tagInfo is an Object given by nfc service when tag is dispatched. // see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'mifareClassic' correctly.
tag.MifareClassicTag(taginfo).restoreFromBlock(blockIndex).then(function (errcode){ let blockIndex = 1; // change it to be correct index.
console.log(JSON.stringify(errcode)) mifareClassic.restoreFromBlock(blockIndex)
}) .then((data) => {
console.log("mifareClassic restoreFromBlock data: " + data);
}).catch((err)=> {
console.log("mifareClassic isExtendrestoreFromBlockedApduSupported err: " + err);
});
``` ```
### MifareClassicTag.restoreFromBlock<sup>9+</sup> ### MifareClassicTag.restoreFromBlock<sup>9+</sup>
...@@ -1302,11 +1392,15 @@ restoreFromBlock(blockIndex: number, callback: AsyncCallback\<number>): void ...@@ -1302,11 +1392,15 @@ restoreFromBlock(blockIndex: number, callback: AsyncCallback\<number>): void
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
// tagInfo is an Object given by nfc service when tag is dispatched. // see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'mifareClassic' correctly.
tag.MifareClassicTag(taginfo).restoreFromBlock(blockIndex, function (error, errcode) { let blockIndex = 1; // change it to be correct index.
console.log(JSON.stringify(error)) mifareClassic.restoreFromBlock(blockIndex, (err, data)=> {
console.log(JSON.stringify(errcode)) if (err) {
}) console.log("mifareClassic restoreFromBlock err: " + err);
} else {
console.log("mifareClassic restoreFromBlock data: " + data);
}
});
``` ```
### MifareClassicTag.getSectorCount<sup>9+</sup> ### MifareClassicTag.getSectorCount<sup>9+</sup>
...@@ -1330,8 +1424,9 @@ getSectorCount(): number ...@@ -1330,8 +1424,9 @@ getSectorCount(): number
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
// tagInfo is an Object given by nfc service when tag is dispatched. // see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'mifareClassic' correctly.
let setorCount = tag.MifareClassicTag(taginfo).getSectorCount(); let sectorCount = mifareClassic.getSectorCount();
console.log("mifareClassic sectorCount: " + sectorCount);
``` ```
### MifareClassicTag.getBlockCountInSector<sup>9+</sup> ### MifareClassicTag.getBlockCountInSector<sup>9+</sup>
...@@ -1361,13 +1456,14 @@ getBlockCountInSector(sectorIndex: number): number ...@@ -1361,13 +1456,14 @@ getBlockCountInSector(sectorIndex: number): number
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
// tagInfo is an Object given by nfc service when tag is dispatched. // see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'mifareClassic' correctly.
let blockNumber = tag.MifareClassicTag(taginfo).getBlockCountInSector(sectorIndex); let blockCountInSector = mifareClassic.getBlockCountInSector();
console.log("mifareClassic blockCountInSector: " + blockCountInSector);
``` ```
### MifareClassicTag.getType<sup>9+</sup> ### MifareClassicTag.getType<sup>9+</sup>
getType(): [MifareClassicType](#mifareclassictype9) getType(): [MifareClassicType](js-apis-nfcTag.md#mifareclassictype9)
获取MifareClassic标签的类型。 获取MifareClassic标签的类型。
...@@ -1379,22 +1475,23 @@ getType(): [MifareClassicType](#mifareclassictype9) ...@@ -1379,22 +1475,23 @@ getType(): [MifareClassicType](#mifareclassictype9)
| **类型** | **说明** | | **类型** | **说明** |
| ------------------ | --------------------------| | ------------------ | --------------------------|
| [MifareClassicType](#mifareclassictype9) | MifareClassic标签的类型。| | [MifareClassicType](js-apis-nfcTag.md#mifareclassictype9) | MifareClassic标签的类型。|
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
// tagInfo is an Object given by nfc service when tag is dispatched. // see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'mifareClassic' correctly.
let type = tag.MifareClassicTag(taginfo).getType(); let getType = mifareClassic.getType();
console.log("mifareClassic getType: " + getType);
``` ```
### MifareClassicTag.getTagSize<sup>9+</sup> ### MifareClassicTag.getTagSize<sup>9+</sup>
getTagSize(): number getTagSize(): number
获取标签的大小(字节),具体请参见[MifareTagSize](#mifaretagsize9) 获取标签的大小(字节),具体请参见[MifareClassicSize](js-apis-nfcTag.md#mifareclassicsize9)
**需要权限**:ohos.permission.NFC_TAG **需要权限**:ohos.permission.NFC_TAG
...@@ -1404,35 +1501,18 @@ getTagSize(): number ...@@ -1404,35 +1501,18 @@ getTagSize(): number
| **类型** | **说明** | | **类型** | **说明** |
| ------------------ | --------------------------| | ------------------ | --------------------------|
| number | 标签的大小,单位为字节,请参见[MifareTagSize](#mifaretagsize9)。| | number | 标签的大小,单位为字节,请参见[MifareClassicSize](js-apis-nfcTag.md#mifareclassicsize9)。|
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
// tagInfo is an Object given by nfc service when tag is dispatched. // see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'mifareClassic' correctly.
let size = tag.MifareClassicTag(taginfo).getTagSize(); let tagSize = mifareClassic.getTagSize();
console.log("mifareClassic tagSize: " + tagSize);
``` ```
## MifareClassicType<sup>9+</sup>
| **参数名** | **值** | **说明** |
| -------- | -------- | -------- |
| TYPE_UNKNOWN | -1 | 未知Mifare类型。 |
| TYPE_CLASSIC | 0 | Mifare Classic类型。|
| TYPE_PLUS | 1 | Mifare Plus类型。|
| TYPE_PRO | 2 | Mifare Pro类型。 |
## MifareTagSize<sup>9+</sup>
| **参数名** | **值** | **说明** |
| -------- | -------- | -------- |
| MC_SIZE_MINI | 320 | 每个标签5个扇区,每个扇区4个块。 |
| MC_SIZE_1K | 1024 | 每个标签16个扇区,每个扇区4个块。|
| MC_SIZE_2K | 2048 | 每个标签32个扇区,每个扇区4个块。 |
| MC_SIZE_4K | 4096 | 每个标签40个扇区,每个扇区4个块。|
### MifareClassicTag.isEmulatedTag<sup>9+</sup> ### MifareClassicTag.isEmulatedTag<sup>9+</sup>
isEmulatedTag(): boolean isEmulatedTag(): boolean
...@@ -1454,8 +1534,9 @@ isEmulatedTag(): boolean ...@@ -1454,8 +1534,9 @@ isEmulatedTag(): boolean
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
// tagInfo is an Object given by nfc service when tag is dispatched. // see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'mifareClassic' correctly.
let isEmulated = tag.MifareClassicTag(taginfo).isEmulatedTag(); let isEmulatedTag = mifareClassic.isEmulatedTag();
console.log("mifareClassic isEmulatedTag: " + isEmulatedTag);
``` ```
### MifareClassicTag.getBlockIndex<sup>9+</sup> ### MifareClassicTag.getBlockIndex<sup>9+</sup>
...@@ -1485,8 +1566,10 @@ getBlockIndex(sectorIndex: number): number ...@@ -1485,8 +1566,10 @@ getBlockIndex(sectorIndex: number): number
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
// tagInfo is an Object given by nfc service when tag is dispatched. // see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'mifareClassic' correctly.
let index = tag.MifareClassicTag(taginfo).getBlockIndex(sectorIndex); let sectorIndex = 1; // change it to be correct index.
let blockIndex = mifareClassic.getBlockIndex(sectorIndex);
console.log("mifareClassic blockIndex: " + blockIndex);
``` ```
### MifareClassicTag.getSectorIndex<sup>9+</sup> ### MifareClassicTag.getSectorIndex<sup>9+</sup>
...@@ -1516,8 +1599,10 @@ getSectorIndex(blockIndex: number): number ...@@ -1516,8 +1599,10 @@ getSectorIndex(blockIndex: number): number
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
// tagInfo is an Object given by nfc service when tag is dispatched. // see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'mifareClassic' correctly.
let index = tag.MifareClassicTag(taginfo).getSectorIndex(blockIndex); let blockIndex = 1; // change it to be correct index.
let sectorIndex = mifareClassic.getSectorIndex(blockIndex);
console.log("mifareClassic sectorIndex: " + sectorIndex);
``` ```
## MifareUltralightTag<sup>9+</sup> ## MifareUltralightTag<sup>9+</sup>
...@@ -1530,7 +1615,7 @@ TagSession是所有Nfc tag 技术类型的基类, 提供建立连接和发送 ...@@ -1530,7 +1615,7 @@ TagSession是所有Nfc tag 技术类型的基类, 提供建立连接和发送
### MifareUltralightTag.readMultiplePages<sup>9+</sup> ### MifareUltralightTag.readMultiplePages<sup>9+</sup>
readMultiplePages(pageIndex: number): Promise\<string> readMultiplePages(pageIndex: number): Promise\<number[]>
阅读4页,共16字节。页面大小为4字节。使用promise方式作为异步方法。 阅读4页,共16字节。页面大小为4字节。使用promise方式作为异步方法。
...@@ -1548,7 +1633,7 @@ readMultiplePages(pageIndex: number): Promise\<string> ...@@ -1548,7 +1633,7 @@ readMultiplePages(pageIndex: number): Promise\<string>
| **类型** | **说明** | | **类型** | **说明** |
| ------------------ | --------------------------| | ------------------ | --------------------------|
| Promise\<string> | 读取的4页的数据。 | | Promise\<number[]> | 读取的4页的数据。 |
**示例:** **示例:**
...@@ -1556,15 +1641,19 @@ readMultiplePages(pageIndex: number): Promise\<string> ...@@ -1556,15 +1641,19 @@ readMultiplePages(pageIndex: number): Promise\<string>
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
// tagInfo is an Object given by nfc service when tag is dispatched. // see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'mifareUltralight' correctly.
tag.MifareUltralightTag(taginfo).readMultiplePages(pageIndex).then(function (data){ let pageIndex = 1; // change it to be correct index.
console.log("data: " + data) mifareUltralight.readMultiplePages(pageIndex)
}) .then((data) => {
console.log("mifareUltralight readMultiplePages data: " + data);
}).catch((err)=> {
console.log("mifareUltralight readMultiplePages err: " + err);
});
``` ```
### MifareUltralightTag.readMultiplePages<sup>9+</sup> ### MifareUltralightTag.readMultiplePages<sup>9+</sup>
readMultiplePages(pageIndex: number, callback: AsyncCallback\<string>): void readMultiplePages(pageIndex: number, callback: AsyncCallback\<number[]>): void
阅读4页,共16字节。页面大小为4字节。使用callback方式作为异步方法。 阅读4页,共16字节。页面大小为4字节。使用callback方式作为异步方法。
...@@ -1577,23 +1666,27 @@ readMultiplePages(pageIndex: number, callback: AsyncCallback\<string>): void ...@@ -1577,23 +1666,27 @@ readMultiplePages(pageIndex: number, callback: AsyncCallback\<string>): void
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | -------------------------------------- | | -------- | ----------------------- | ---- | -------------------------------------- |
| pageIndex | number | 是 | 要读取页面的索引 | | pageIndex | number | 是 | 要读取页面的索引 |
| callback | AsyncCallback\<string> | 是 | 回调函数。 | | callback | AsyncCallback\<number[]> | 是 | 回调函数。 |
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
// tagInfo is an Object given by nfc service when tag is dispatched. // see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'mifareUltralight' correctly.
tag.MifareUltralightTag(taginfo).readMultiplePages(pageIndex, function (error, data) { let pageIndex = 1; // change it to be correct index.
console.log(JSON.stringify(error)) mifareUltralight.readMultiplePages(pageIndex, (err, data)=> {
console.log(JSON.stringify(data)) if (err) {
}) console.log("mifareUltralight readMultiplePages err: " + err);
} else {
console.log("mifareUltralight readMultiplePages data: " + data);
}
});
``` ```
### MifareUltralightTag.writeSinglePages<sup>9+</sup> ### MifareUltralightTag.writeSinglePages<sup>9+</sup>
writeSinglePages(pageIndex: number, data: string): Promise\<number> writeSinglePages(pageIndex: number, data: number[]): Promise\<number>
写入一页数据,页面大小为4字节。使用promise方式作为异步方法。 写入一页数据,页面大小为4字节。使用promise方式作为异步方法。
...@@ -1606,7 +1699,7 @@ writeSinglePages(pageIndex: number, data: string): Promise\<number> ...@@ -1606,7 +1699,7 @@ writeSinglePages(pageIndex: number, data: string): Promise\<number>
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | -------------------------------------- | | -------- | ----------------------- | ---- | -------------------------------------- |
| pageIndex | number | 是 | 要写入页面的索引。 | | pageIndex | number | 是 | 要写入页面的索引。 |
| data | string | 是 | 要写入页面的数据内容。 | | data | number[] | 是 | 要写入页面的数据内容。 |
**返回值:** **返回值:**
...@@ -1619,15 +1712,20 @@ writeSinglePages(pageIndex: number, data: string): Promise\<number> ...@@ -1619,15 +1712,20 @@ writeSinglePages(pageIndex: number, data: string): Promise\<number>
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
// tagInfo is an Object given by nfc service when tag is dispatched. // see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'mifareUltralight' correctly.
tag.MifareUltralightTag(taginfo).writeSinglePages(pageIndex, data).then(function (errcode){ let pageIndex = 1; // change it to be correct index.
console.log(JSON.stringify(errcode)) let data = [0x01, 0x02, ...]; // change it to be correct raw data.
}) mifareUltralight.writeSinglePages(pageIndex, data)
.then((data) => {
console.log("mifareUltralight writeSinglePages data: " + data);
}).catch((err)=> {
console.log("mifareUltralight writeSinglePages err: " + err);
});
``` ```
### MifareUltralightTag.writeSinglePages<sup>9+</sup> ### MifareUltralightTag.writeSinglePages<sup>9+</sup>
writeSinglePages(pageIndex: number, data: string, callback: AsyncCallback\<number>): void writeSinglePages(pageIndex: number, data: number[], callback: AsyncCallback\<number>): void
写入一页数据,页面大小为4字节。使用callback方式作为异步方法。 写入一页数据,页面大小为4字节。使用callback方式作为异步方法。
...@@ -1640,7 +1738,7 @@ writeSinglePages(pageIndex: number, data: string, callback: AsyncCallback\<numbe ...@@ -1640,7 +1738,7 @@ writeSinglePages(pageIndex: number, data: string, callback: AsyncCallback\<numbe
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | ------------------------ | | -------- | ----------------------- | ---- | ------------------------ |
| pageIndex | number | 是 | 要写入页面的索引。 | | pageIndex | number | 是 | 要写入页面的索引。 |
| data | string | 是 | 要写入页面的数据内容。 | | data | number[] | 是 | 要写入页面的数据内容。 |
| callback|AsyncCallback\<number> |是| 回调函数。 | | callback|AsyncCallback\<number> |是| 回调函数。 |
**示例:** **示例:**
...@@ -1648,18 +1746,23 @@ writeSinglePages(pageIndex: number, data: string, callback: AsyncCallback\<numbe ...@@ -1648,18 +1746,23 @@ writeSinglePages(pageIndex: number, data: string, callback: AsyncCallback\<numbe
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
// tagInfo is an Object given by nfc service when tag is dispatched. // see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'mifareUltralight' correctly.
tag.MifareUltralightTag(taginfo).writeSinglePages(pageIndex, data, function (error, errcode) { let pageIndex = 1; // change it to be correct index.
console.log(JSON.stringify(error)) let data = [0x01, 0x02, ...]; // change it to be correct raw data.
console.log(JSON.stringify(errcode)) mifareUltralight.writeSinglePages(pageIndex, data, (err, data)=> {
}) if (err) {
console.log("mifareUltralight writeSinglePages err: " + err);
} else {
console.log("mifareUltralight writeSinglePages data: " + data);
}
});
``` ```
### MifareUltralightTag.getType<sup>9+</sup> ### MifareUltralightTag.getType<sup>9+</sup>
getType(): MifareUltralightType getType(): MifareUltralightType
获取MifareUltralight标签的类型,以字节形式返回,具体请参见 [MifareUltralightType](#mifareultralighttype9) 获取MifareUltralight标签的类型,以字节形式返回,具体请参见 [MifareUltralightType](js-apis-nfcTag.md#mifareultralighttype9)
**需要权限**:ohos.permission.NFC_TAG **需要权限**:ohos.permission.NFC_TAG
...@@ -1669,25 +1772,18 @@ getType(): MifareUltralightType ...@@ -1669,25 +1772,18 @@ getType(): MifareUltralightType
| **类型** | **说明** | | **类型** | **说明** |
| ------------------ | --------------------------| | ------------------ | --------------------------|
| MifareUltralightType | MifareUltralight标签的类型, 具体请参见 [MifareUltralightType](#mifareultralighttype9)。| | MifareUltralightType | MifareUltralight标签的类型, 具体请参见 [MifareUltralightType](js-apis-nfcTag.md#mifareultralighttype9)。|
**示例:** **示例:**
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
// tagInfo is an Object given by nfc service when tag is dispatched. // see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'mifareUltralight' correctly.
let type = tag.MifareUltralightType(taginfo).getType(); let getType = mifareClassic.getType();
console.log("mifareUltralight getType: " + getType);
``` ```
### MifareUltralightType<sup>9+</sup>
| **参数名** | **值** | **说明** |
| -------- | -------- | -------- |
| TYPE_UNKOWN | -1 | 未知的 Mifare 类型。 |
| TYPE_ULTRALIGHT | 1 | Mifare Ultralight类型。|
| TYPE_ULTRALIGHT_C | 2 | Mifare UltralightC 类型。 |
## NdefFormatableTag<sup>9+</sup> ## NdefFormatableTag<sup>9+</sup>
NdefFormatableTag为NDEF formattable的标签提供格式化操作,继承自TagSession。 NdefFormatableTag为NDEF formattable的标签提供格式化操作,继承自TagSession。
...@@ -1723,10 +1819,18 @@ format(message: [NdefMessage](#ndefmessage9)): Promise\<number> ...@@ -1723,10 +1819,18 @@ format(message: [NdefMessage](#ndefmessage9)): Promise\<number>
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
// tagInfo is an Object given by nfc service when tag is dispatched. // see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'ndef' correctly.
tag.NdefFormatableTag(taginfo).format(message).then(function (errcode){ let data = [0x01, 0x02, ...]; // change it to be correct raw data.
console.log(JSON.stringify(errcode)) let ndefmessage = ndef.createNdefMessage(data);
})
// see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'ndefFormatable' correctly.
ndefFormatable.format(ndefmessage, (err, data)=> {
if (err) {
console.log("ndefFormatable format err: " + err);
} else {
console.log("ndefFormatable format data: " + data);
}
});
``` ```
### NdefFormatableTag.format<sup>9+</sup> ### NdefFormatableTag.format<sup>9+</sup>
...@@ -1757,11 +1861,18 @@ format(message: [NdefMessage](#ndefmessage9), callback: AsyncCallback\<number>): ...@@ -1757,11 +1861,18 @@ format(message: [NdefMessage](#ndefmessage9), callback: AsyncCallback\<number>):
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
// tagInfo is an Object given by nfc service when tag is dispatched. // see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'ndef' correctly.
tag.NdefFormatableTag(taginfo).format(message, function (error, errcode) { let data = [0x01, 0x02, ...]; // change it to be correct raw data.
console.log(JSON.stringify(error)) let ndefmessage = ndef.createNdefMessage(data);
console.log(JSON.stringify(errcode))
}) // see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'ndefFormatable' correctly.
ndefFormatable.format(ndefmessage, (err, data)=> {
if (err) {
console.log("ndefFormatable format err: " + err);
} else {
console.log("ndefFormatable format data: " + data);
}
});
``` ```
### NdefFormatableTag.formatReadOnly<sup>9+</sup> ### NdefFormatableTag.formatReadOnly<sup>9+</sup>
...@@ -1791,10 +1902,18 @@ formatReadOnly(message: [NdefMessage](#ndefmessage9)): Promise\<number> ...@@ -1791,10 +1902,18 @@ formatReadOnly(message: [NdefMessage](#ndefmessage9)): Promise\<number>
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
// tagInfo is an Object given by nfc service when tag is dispatched. // see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'ndef' correctly.
tag.NdefFormatableTag(taginfo).formatReadOnly(message).then(function (errcode){ let data = [0x01, 0x02, ...]; // change it to be correct raw data.
console.log(JSON.stringify(errcode)) let ndefmessage = ndef.createNdefMessage(data);
})
// see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'ndefFormatable' correctly.
ndefFormatable.formatReadOnly(ndefmessage, (err, data)=> {
if (err) {
console.log("ndefFormatable formatReadOnly err: " + err);
} else {
console.log("ndefFormatable formatReadOnly data: " + data);
}
});
``` ```
### NdefFormatableTag.formatReadOnly<sup>9+</sup> ### NdefFormatableTag.formatReadOnly<sup>9+</sup>
...@@ -1825,9 +1944,16 @@ formatReadOnly(message: [NdefMessage](#ndefmessage9), callback: AsyncCallback\<n ...@@ -1825,9 +1944,16 @@ formatReadOnly(message: [NdefMessage](#ndefmessage9), callback: AsyncCallback\<n
```js ```js
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
// tagInfo is an Object given by nfc service when tag is dispatched. // see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'ndef' correctly.
tag.NdefFormatableTag(taginfo).formatReadOnly(message, function (error, errcode) { let data = [0x01, 0x02, ...]; // change it to be correct raw data.
console.log(JSON.stringify(error)) let ndefmessage = ndef.createNdefMessage(data);
console.log(JSON.stringify(errcode))
}) // see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'ndefFormatable' correctly.
ndefFormatable.formatReadOnly(ndefmessage, (err, data)=> {
if (err) {
console.log("ndefFormatable formatReadOnly err: " + err);
} else {
console.log("ndefFormatable formatReadOnly data: " + data);
}
});
``` ```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册