- NFC功能 执行nfcA.transceive后小程序会再次执行onDiscovered的监听函数?
const app = getApp() Page({ nfc: null, onLoad: function () { const nfc = wx.getNFCAdapter() this.nfc = nfc function discoverHandler(res) { if (res.techs.includes(nfc.tech.ndef)) { console.log(res.messages) //const ndef = nfc.getNdef() //ndef.writeNdefMessage({ // uris: [''], // complete(res) { // console.log('res:', res) // } //}) //return } if (res.techs.includes(nfc.tech.nfcA)) { const nfcA = nfc.getNfcA() nfcA.connect({ success() { console.log("discoverHandler connect success") }, fail() { console.log("discoverHandler connect fail") } }) let array = [0x47, 0x11] var arrayBuffer = new Uint8Array(array).buffer; nfcA.transceive({ data: arrayBuffer, complete(res) { console.log('res:', res) } }) return } } nfc.onDiscovered(discoverHandler) nfc.startDiscovery({ fail(err) { console.log('failed to discover:', err) } }) }, onHide() { if (this.nfc) { this.nfc.stopDiscovery() } } }) 使用以上代码测试,程序会循环执行discoverHandler->transceive->discoverHandler->transceive,见附件图片log信息 [图片]
01-30 - 基础库2.11.2新增的NFC读写,NFC读卡功能如何使用,有没有demo参考?
基础库2.11.2新增的NFC读写,NFC读卡功能如何使用,有没有demo参考?
2020-07-17