Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
687b3a6e
D
Docs
项目概览
OpenHarmony
/
Docs
大约 1 年 前同步成功
通知
159
Star
292
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
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 @@
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> 本模块首批接口从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 @@
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> 本模块首批接口从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 @@
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> 本模块首批接口从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
此差异已折叠。
点击以展开。
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录