onLoad: function () {
const nfc = wx.getNFCAdapter()
this.nfc = nfc
console.log(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
}
console.log('res.techs',res.techs)
try {
if (res.techs.includes(nfc.tech.nfcA)) {
const nfcA = nfc.getNFCA()
nfcA.transceive({
data: new ArrayBuffer(0),
complete(res) {
console.log('res:', res)
}
})
return
}
} catch (error) {
console.error(error)
}
try {
if (res.techs.includes(nfc.tech.mifareClassic)) {
const nfcA = nfc.getMifareClassic()
nfcA.transceive({
data: new ArrayBuffer(0),
complete(res) {
console.log('res:', res)
}
})
return
}
} catch (error) {
}
}
nfc.onDiscovered(discoverHandler)
nfc.startDiscovery({
success(e){
console.log('success to discover:',e)
},
complete(e){
console.log('complete to discover:',e)
},
fail(err) {
console.log('failed to discover:', err)
}
})
},
请具体描述问题出现的流程,并提供能复现问题的简单代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)。