onLoad(options) {
this.intNfc()
},
onNFCReadMessage: function (e) {
console.log(JSON.stringify(e))
if (1 == e.messageType) {
wx.showModal({
title: 'NFC-Id',
content: JSON.stringify(e),
})
} else if (2 == e.messageType) {
console.log('Auto-Stop')
wx.showModal({
title: 'NFC-Auto-Stop',
content: JSON.stringify(e),
})
}
},
methods: {
intNfc() {
wx.qy.startNFCReader({
success(res){
console.log('=== checkNfcSupport: nfc.startDiscovery success, res = ', res)
that.supportNfc = true
console.log(res, "startNFCReader-supportNfc")
if (that.nfc === null){
console.log(res, "startNFCReader")
// that.nfc = new Nfc(that.adapter)
}
that.returnHome()
},
fail(err) {
console.log('=== checkNfcSupport nfc.startDiscovery failed to discover:', err)
that.supportNfc = false
let msg = ''
if (err !== null && typeof err !== 'undefined'){
if (typeof err === 'object'){
err = JSON.stringify(err)
}
if (err.indexOf("13000") > -1){ //设备不支持NFC
that.supportNfc = false
app.globalData.CardReader.updateMode('qrCode') // 不支持切换至二维码 20230306
} else if (err.indexOf("13001") > -1){ //系统NFC开关未打开
//未打开时自动寻找蓝牙,但是需要提示
that.supportNfc = true
// wx.showModal({
// title: '提示',
// content: '系统NFC开关未打开, 请您打开手机NFC和赋予微信访问NFC的权限'
// })
msg = '系统NFC开关未打开, 请您打开手机NFC'
}
}
if (that.supportNfc){
if (that.nfc === null){
console.log(" fail: mobile support NFC, using nfc -- supportNfc")
// that.nfc = new Nfc(that.adapter)
}
} else {
if (that.nfcBle === null){
console.log(" fail: mobile not support NFC, using nfcBle")
//that.nfcBle = new NfcBle()
}
}
if (!that.supportNfc){
that.notSupportNFC()
} else {
if (msg.length > 1){
// that.showModal(msg) // 不用提示 20230306
that.returnHome()
} else {
that.returnHome()
}
}
}
})
},
}
- 发布:2023-03-24 09:56
- 更新:2023-04-03 10:25
- 阅读:617
产品分类: uniapp/小程序/微信
PC开发环境操作系统: Windows
PC开发环境操作系统版本号: win10
第三方开发者工具版本号: 1.06.2210310
基础库版本号: 2.20.3
项目创建方式: CLI
CLI版本号: 2.6.11
示例代码:
操作步骤:
开启nfc,读取nfc卡片
开启nfc,读取nfc卡片
预期结果:
进入到onNFCReadMessage监听中,打印日志
进入到onNFCReadMessage监听中,打印日志
实际结果:
Error in onNFCReadMessage hook: "typeError: cannot read property 'apply' of undefined"
Error in onNFCReadMessage hook: "typeError: cannot read property 'apply' of undefined"
3 个回复
最佳回复
DCloud_UNI_WZF
HBuilderX 3.7.12 (cli 2.0.2-alpha-3071220230331001) 已修复
DCloud_UNI_WZF
vue2 复现该问题,感谢反馈,已加分
DCloud_UNI_WZF
临时解决方案:
替换 HBuilderX/plugins/uniapp-cli/node_modules/@dcloudio/vue-cli-plugin-uni/packages/mp-vue/dist/mp.runtime.esm.js 为附件文件
1***@qq.com (作者)
没有好啊,vue-cli创建的,不是hbuilderX直接创建的
2023-03-31 19:27
DCloud_UNI_WZF
回复 1***@qq.com: 文件替换了吗
2023-03-31 19:39
1***@qq.com (作者)
回复 DCloud_UNI_WZF: 换了,可以,那就只能手动替换node_modules里面的这个文件了,什么时候修复呢
2023-04-03 09:47