教程 框架 组件 接口 工具 其他

NfcF 1100+

方法

NfcF.close(OBJECT)

断开连接

参数:

参数名类型必填说明
successFunction成功回调
failFunction失败回调
completeFunction调用结束

示例:

nfcf.close({
  success: function() {
    console.log(`handling success`)
  },
  fail: function(data, code) {
    console.log(`handling fail, code = ${code}`)
  },
  complete: function() {
    console.log(`handling complete`)
  }
})

NfcF.connect(OBJECT)

连接 NFC 标签

参数:

参数名类型必填说明
successFunction成功回调
failFunction失败回调
completeFunction调用结束

示例:

nfcf.connect({
  success: function() {
    console.log(`handling success`)
  },
  fail: function(data, code) {
    console.log(`handling fail, code = ${code}`)
  },
  complete: function() {
    console.log(`handling complete`)
  }
})

NfcF.getMaxTransceiveLength(OBJECT)

获取最大传输长度

参数:

参数名类型必填说明
successFunction成功回调
failFunction失败回调
completeFunction调用结束
success 返回值对象参数:
参数名类型说明
lengthnumber最大传输长度

示例:

nfcf.getMaxTransceiveLength({
  success: function(data) {
    console.log(`handling success, length = ` + data.length)
  },
  fail: function(data, code) {
    console.log(`handling fail, code = ${code}`)
  },
  complete: function() {
    console.log(`handling complete`)
  }
})

NfcF.isConnected(OBJECT)

获取当前标签的连接状态

参数:

参数名类型必填说明
successFunction成功回调
failFunction失败回调
completeFunction调用结束
success 返回值对象参数:
参数名类型说明
isConnectedBoolean是否已经建立了连接

示例:

nfcf.isConnected({
  success: function(data) {
    console.log(`handling success, isConnected = ` + data.isConnected)
  },
  fail: function(data, code) {
    console.log(`handling fail, code = ${code}`)
  },
  complete: function() {
    console.log(`handling complete`)
  }
})

NfcF.setTimeout(OBJECT)

设置超时时间

参数:

参数名类型必填说明
timeoutNumber超时时间(ms)
successFunction成功回调
failFunction失败回调
completeFunction调用结束

示例:

nfcf.setTimeout({
  timeout: 1000,
  success: function(data) {
    console.log(`handling success`)
  },
  fail: function(data, code) {
    console.log(`handling fail, code = ${code}`)
  },
  complete: function() {
    console.log(`handling complete`)
  }
})

NfcF.transceive(OBJECT)

发送数据

参数:

参数名类型必填说明
dataArrayBuffer需要传递的二进制数据
successFunction成功回调
failFunction失败回调
completeFunction调用结束
success 返回值对象参数:
参数名类型说明
dataArrayBuffer标签返回结果

示例:

let arrayBuffer = new ArrayBuffer(1)
let dataView = new DataView(arrayBuffer)
dataView.setUint8(0, 0x60)
nfcf.transceive({
  data: arrayBuffer,
  success: function(data) {
    console.log(`handling success, result = ` + new Int8Array(data.data))
  },
  fail: function(data, code) {
    console.log(`handling fail, code = ${code}`)
  },
  complete: function() {
    console.log(`handling complete`)
  }
})

条匹配 "" 的结果

    没有搜索到与 "" 相关的内容