微信小程序nfc指令异常记录

小程序nfc相关代码:

javascript 复制代码
readEvent(){
    
    wx.getNFCAdapter().startDiscovery({
      success:(res)=>{
        console.log('--------------start--------')
        console.log(res);
        wx.getNFCAdapter().onDiscovered(
          callback=>{
            console.log('------------onDiscovered----------')
            console.log(callback);
            console.log(Array.from(new Uint8Array(callback.id)))
            console.log('------------getNfcA----------')
            console.log('------------connect----------')
            wx.getNFCAdapter().getNfcA().connect({
              success:(res)=>{
                console.info(res)
                console.log('------------transceive----------')
                wx.getNFCAdapter().getNfcA().transceive({
                  data: new Uint8Array([0x30, 0x04]).buffer, // 必须要传入 ArrayBuffer
                  success: (res) => {
                      // res.data 是 ArrayBuffer,转成数组方便查看
                      console.log(Array.from(new Uint8Array(res.data)));
                  },
                  fail:(err)=>{
                    console.log(err)
                  }
              })
              
              },
              fail:(err)=>{
                console.error(err);
              }
            })
          }
        );
      },
      fail:(err)=>{

      }
    });
    
  },

connect 成功但是指令报错,报错信息:

transceive:fail:system internal error:tag was lost

解决方式,替换NfcA

javascript 复制代码
readEvent(){
    
    wx.getNFCAdapter().startDiscovery({
      success:(res)=>{
        console.log('--------------start--------')
        console.log(res);
        wx.getNFCAdapter().onDiscovered(
          callback=>{
            console.log('------------onDiscovered----------')
            console.log(callback);
            console.log(Array.from(new Uint8Array(callback.id)))
            console.log('------------getNfcA----------')
            console.log('------------connect----------')
            wx.getNFCAdapter().getIsoDep().connect({
              success:(res)=>{
                console.info(res)
                console.log('------------transceive----------')
                wx.getNFCAdapter().getIsoDep().transceive({
                  data: new Uint8Array([0x30, 0x04]).buffer, // 必须要传入 ArrayBuffer
                  success: (res) => {
                      // res.data 是 ArrayBuffer,转成数组方便查看
                      console.log(Array.from(new Uint8Array(res.data)));
                  },
                  fail:(err)=>{
                    console.log(err)
                  }
              })
              
              },
              fail:(err)=>{
                console.error(err);
              }
            })
          }
        );
      },
      fail:(err)=>{

      }
    });
    
  },
相关推荐
拖孩11 小时前
用 AI 重解千年观音灵签,做了一个微信小程序,每天摇一摇,命运给你回应
前端·后端·微信小程序
黄华SJ520it13 小时前
顶俏洗衣液模式制度开发介绍:S2B2C社交分销+多门店核销系统全解析
前端·数据库·小程序·零售·系统开发
北极糊的狐16 小时前
钉钉小程序报错data.formatTime is not a function是因为 axml 模板中不能直接调用 Page 内自定义方法!
java·小程序·钉钉
java1234_小锋16 小时前
【免费】微信小程序网约车(打车,在线叫车,移动出行)系统(SpringBoot4+Vue3) 锋哥原创出品,必属精品
微信小程序·网约车·在线叫车·移动出行
show4332 天前
多格式导出怎么做?2026免费小程序TXT/SRT实践
开发语言·小程序·c#
AI砖家2 天前
AI编程—微信小程序开发规范
微信小程序·小程序·notepad++·ai编程
show4332 天前
2026小程序端视频转文字技术对比:识别引擎精度实测
小程序·音视频
sam-zy2 天前
微信小程序+ESP8266+Arduino 开发智能插座,有本地OTA功能
微信小程序·小程序
A24207349303 天前
微信小程序开发:常用基础语法与指令详解
微信小程序·小程序·notepad++
黄华SJ520it3 天前
青蓝送水类型社交裂变小程序系统技术拆解
小程序·系统开发