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