onShow: function () {
var that = this;
var adapter = wx.getNFCAdapter();
console.log(adapter);
adapter.startDiscovery({
success: res => {
that.setData({
title:'success-->请将设备放入识别区NFC'
})
console.log('开始监听贴卡',res);
adapter.onDiscovered(res => {
console.log('读到卡片了', res);
let arrbuf = that.strToArrayBuffer('GET DATA')
if(res.techs.includes(adapter.tech.nfcB)){
console.log('发现'+adapter.tech.nfcB+'卡');
let nfcB = adapter.getNfcB();
app.nfcB = nfcB;
nfcB.connect({
success: function(res){
console.log('设备已连接', res)
nfcB.transceive({
data:arrbuf,
success: function(res){
console.log('发送数据成功, 接收数据如下:', res);
that.setData({
title:'发送数据成功, 接收数据...'
})
},
fail: function(err){
console.log('发送数据失败', err);
}
})
},
fail: function(err){
console.log('设备联接错误', err);
}
});
}
});
},
fail: error => {
that.setData({
title:'错误信息-->' + error.errMsg
})
console.log(error);
},
complete: res => {
console.log('complete');
console.log(res);
}
});
},