uniApp使用hexiii-nfc.js实现nfc刷ic功能

1.我们先找到这个nfc的插件,:下载地址,也可以直接拿出里面的hexiii-nfc.js文件,楼主就是拿的js文件
2.在js文件中使用uniApp的uni.$emit事件把值传递出去

read(intent) {
		// toast('请勿移开标签正在读取数据');
		let that = this;
		// NFC id
		let bytesId = intent.getByteArrayExtra(NfcAdapter.EXTRA_ID);
		let nfc_id = that.byteArrayToHexString(bytesId);
		console.log('nfc_id:', nfc_id);
		let Parcelable = plus.android.importClass("android.os.Parcelable");
		// let rawmsgs = intent.getParcelableArrayExtra("android.nfc.extra.NDEF_MESSAGES");
		let rawmsgs = intent.getParcelableArrayExtra();
		// toast('NFC 数据:' + nfc_id);
		if(nfc_id){
			// 通过uniApp的 $emit方法 将读取到的id广播出去  
			uni.$emit('nfc_id',{
				nfc_id:nfc_id
			})
		}else{
			toast('数据读取失败');
		}

2.在需要的页面引入一次

import nfc from '../../static/until/hexiii-nfc.js';

3.在onLoad 函数中使用开启监听

onLoad(options) {
	// 开启监听
	uni.$on('nfc_id', id => {
		if (id.nfc_id !== '') {
			// 逻辑代码
			this.searchStudent(0, id.nfc_id);
		}
	});
}

4.在卸载当前页面的时候关闭监听

onUnload() {
	// 页面卸载的时候 卸载监听刷ic卡
	uni.$off('nfc_id');
},
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值