Ndef
Ndef 标签
支持情况: 
  
  
 
方法
close
断开连接
支持情况: 
  
  
 
(option?: Option) => Promise<TaroGeneral.NFCError>
| 参数 | 类型 | 
|---|---|
| option | Option | 
connect
连接 NFC 标签
支持情况: 
  
  
 
(option?: Option) => Promise<TaroGeneral.NFCError>
| 参数 | 类型 | 
|---|---|
| option | Option | 
isConnected
检查是否已连接
支持情况: 
  
  
 
(option?: Option) => Promise<TaroGeneral.NFCError>
| 参数 | 类型 | 
|---|---|
| option | Option | 
offNdefMessage
取消监听 Ndef 消息
支持情况: 
  
  
 
(callback: Callback) => void
| 参数 | 类型 | 说明 | 
|---|---|---|
| callback | Callback | 监听 Ndef 消息回调函数 | 
onNdefMessage
监听 Ndef 消息
支持情况: 
  
  
 
(callback: Callback) => void
| 参数 | 类型 | 说明 | 
|---|---|---|
| callback | Callback | 监听 Ndef 消息回调函数 | 
setTimeout
设置超时时间
支持情况: 
  
  
 
(option?: Option) => Promise<TaroGeneral.NFCError>
| 参数 | 类型 | 
|---|---|
| option | Option | 
writeNdefMessage
重写 Ndef 标签内容
支持情况: 
  
  
 
(option?: Option) => Promise<TaroGeneral.NFCError>
| 参数 | 类型 | 
|---|---|
| option | Option | 
参数
close
Option
| 参数 | 类型 | 必填 | 说明 | 
|---|---|---|---|
| complete | (res: TaroGeneral.NFCError) => void | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) | 
| fail | (res: TaroGeneral.NFCError) => void | 否 | 接口调用失败的回调函数 | 
| success | (res: TaroGeneral.NFCError) => void | 否 | 接口调用成功的回调函数 | 
connect
Option
| 参数 | 类型 | 必填 | 说明 | 
|---|---|---|---|
| complete | (res: TaroGeneral.NFCError) => void | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) | 
| fail | (res: TaroGeneral.NFCError) => void | 否 | 接口调用失败的回调函数 | 
| success | (res: TaroGeneral.NFCError) => void | 否 | 接口调用成功的回调函数 | 
isConnected
Option
| 参数 | 类型 | 必填 | 说明 | 
|---|---|---|---|
| complete | (res: TaroGeneral.NFCError) => void | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) | 
| fail | (res: TaroGeneral.NFCError) => void | 否 | 接口调用失败的回调函数 | 
| success | (res: TaroGeneral.NFCError) => void | 否 | 接口调用成功的回调函数 | 
onNdefMessage
Callback
监听 Ndef 消息回调函数
(args: unknown[]) => void
| 参数 | 类型 | 
|---|---|
| args | unknown[] | 
setTimeout
Option
| 参数 | 类型 | 必填 | 说明 | 
|---|---|---|---|
| timeout | number | 是 | 设置超时时间 (ms) | 
| complete | (res: TaroGeneral.NFCError) => void | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) | 
| fail | (res: TaroGeneral.NFCError) => void | 否 | 接口调用失败的回调函数 | 
| success | (res: TaroGeneral.NFCError) => void | 否 | 接口调用成功的回调函数 | 
writeNdefMessage
Option
| 参数 | 类型 | 必填 | 说明 | 
|---|---|---|---|
| uris | string[] | 否 | uri 数组 | 
| texts | string[] | 否 | text 数组 | 
| records | record[] | 否 | 二进制对象数组, 需要指明 id, type 以及 payload (均为 ArrayBuffer 类型) | 
| complete | (res: TaroGeneral.NFCError) => void | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) | 
| fail | (res: TaroGeneral.NFCError) => void | 否 | 接口调用失败的回调函数 | 
| success | (res: TaroGeneral.NFCError) => void | 否 | 接口调用成功的回调函数 | 
record
| 参数 | 类型 | 
|---|---|
| id | ArrayBuffer | 
| type | ArrayBuffer | 
| payload | ArrayBuffer | 
API 支持度
| API | 微信小程序 | H5 | React Native | Harmony | 
|---|---|---|---|---|
| Ndef | ✔️ | |||
| Ndef.close | ✔️ | |||
| Ndef.connect | ✔️ | |||
| Ndef.isConnected | ✔️ | |||
| Ndef.offNdefMessage | ✔️ | |||
| Ndef.onNdefMessage | ✔️ | |||
| Ndef.setTimeout | ✔️ | |||
| Ndef.writeNdefMessage | ✔️ |