title: Ndef

sidebar_label: Ndef

Ndef 标签

支持情况:Ndef - 图1 Ndef - 图2 Ndef - 图3

参考文档

方法

close

断开连接

支持情况:Ndef - 图4 Ndef - 图5 Ndef - 图6

参考文档

  1. (option?: Option) => Promise<TaroGeneral.NFCError>
参数 类型
option Option

connect

连接 NFC 标签

支持情况:Ndef - 图7 Ndef - 图8 Ndef - 图9

参考文档

  1. (option?: Option) => Promise<TaroGeneral.NFCError>
参数 类型
option Option

isConnected

检查是否已连接

支持情况:Ndef - 图10 Ndef - 图11 Ndef - 图12

参考文档

  1. (option?: Option) => Promise<TaroGeneral.NFCError>
参数 类型
option Option

offNdefMessage

取消监听 Ndef 消息

支持情况:Ndef - 图13 Ndef - 图14 Ndef - 图15

参考文档

  1. (callback: Callback) => void
参数 类型 说明
callback Callback 监听 Ndef 消息回调函数

onNdefMessage

监听 Ndef 消息

支持情况:Ndef - 图16 Ndef - 图17 Ndef - 图18

参考文档

  1. (callback: Callback) => void
参数 类型 说明
callback Callback 监听 Ndef 消息回调函数

setTimeout

设置超时时间

支持情况:Ndef - 图19 Ndef - 图20 Ndef - 图21

参考文档

  1. (option?: Option) => Promise<TaroGeneral.NFCError>
参数 类型
option Option

writeNdefMessage

重写 Ndef 标签内容

支持情况:Ndef - 图22 Ndef - 图23 Ndef - 图24

参考文档

  1. (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 消息回调函数

  1. (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
Ndef ✔️
Ndef.close ✔️
Ndef.connect ✔️
Ndef.isConnected ✔️
Ndef.offNdefMessage ✔️
Ndef.onNdefMessage ✔️
Ndef.setTimeout ✔️
Ndef.writeNdefMessage ✔️