Page({
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),
})
}
}
})
- 发布:2022-11-16 10:38
- 更新:2022-11-16 10:38
- 阅读:153
产品分类: uniapp/小程序/微信
PC开发环境操作系统: Windows
PC开发环境操作系统版本号: win10
HBuilderX类型: 正式
HBuilderX版本号: 3.6.4
第三方开发者工具版本号: 1.06.2210310
基础库版本号: 2.20.3
项目创建方式: HBuilderX
示例代码:
操作步骤:
<template>
<view class="gt_content">
<view class="con_NFC">
<text @click="readCardNum">读取卡号</text>
<text @click="stopNFC">tingzhi</text>
</view>
</view>
</template>
<script>
export default {
data() {
return {
}
},
onLoad() {
var nfc = wx.qy.getNFCReaderState({
success: (res) => {
console.log(JSON.stringify(res))
// todo what you want
},
fail: (res) => {
wx.showModal({
title: 'NFC-Not-Support',
content: JSON.stringify(res),
})
}
})
console.log(nfc);
},
onShow() {
},
methods: {
readCardNum() {
wx.qy.startNFCReader({
success: (res) => {
console.log(JSON.stringify(res), 'startNFCReader-success')
wx.showModal({
title: 'NFC-Start',
content: JSON.stringify(res),
})
// wx.onNFCReadMessage()
},
fail: (res) => {
console.log(JSON.stringify(res), 'fail')
}
})
},
stopNFC() {
wx.qy.stopNFCReader({
success: (res) => {
wx.showModal({
title: 'NFC-Stop',
content: JSON.stringify(res),
})
},
fail: (res) => {
console.log(JSON.stringify(res))
}
})
},
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),
})
}
}
}
}
</script>
<template>
<view class="gt_content">
<view class="con_NFC">
<text @click="readCardNum">读取卡号</text>
<text @click="stopNFC">tingzhi</text>
</view>
</view>
</template>
<script>
export default {
data() {
return {
}
},
onLoad() {
var nfc = wx.qy.getNFCReaderState({
success: (res) => {
console.log(JSON.stringify(res))
// todo what you want
},
fail: (res) => {
wx.showModal({
title: 'NFC-Not-Support',
content: JSON.stringify(res),
})
}
})
console.log(nfc);
},
onShow() {
},
methods: {
readCardNum() {
wx.qy.startNFCReader({
success: (res) => {
console.log(JSON.stringify(res), 'startNFCReader-success')
wx.showModal({
title: 'NFC-Start',
content: JSON.stringify(res),
})
// wx.onNFCReadMessage()
},
fail: (res) => {
console.log(JSON.stringify(res), 'fail')
}
})
},
stopNFC() {
wx.qy.stopNFCReader({
success: (res) => {
wx.showModal({
title: 'NFC-Stop',
content: JSON.stringify(res),
})
},
fail: (res) => {
console.log(JSON.stringify(res))
}
})
},
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),
})
}
}
}
}
</script>
预期结果:
正确读卡返回读卡信息
正确读卡返回读卡信息
实际结果:
Error Action
Error Action
bug描述:
Page({
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),
})
}
}
})
这段代码在uniapp中使用 每次读卡均报 Error Action
使用JavaScript 开发的小程序使用该函数无异常
0 个回复