uniapp生物识别示例(人脸识别、指纹识别)

准备工作:

mainfest.json设置勾选:

勾选完成后打 App自定义调试基座测试包

示例代码:

html 复制代码
<template>
	<view class="content">
		<button v-if="supportSoterAuthenticationArray.includes('facial')" @click="SoterAuthenticationFunction('facial')">人脸识别</button>
		<button v-if="supportSoterAuthenticationArray.includes('fingerPrint')" @click="SoterAuthenticationFunction('fingerPrint')">指纹识别</button>
	</view>
</template>

<script setup>
	import { onShow } from '@dcloudio/uni-app'
	import { ref } from 'vue';
	
	onShow(()=>{
		checkIsSupportSoterAuthentication()
	})
	
	const supportSoterAuthenticationArray = ref([])
	const checkIsSupportSoterAuthentication = () => {
		uni.checkIsSupportSoterAuthentication({
			success(res) {
				supportSoterAuthenticationArray.value = res.supportMode
			}
		})
	}
	
	const SoterAuthenticationFunction = (type) => {
		uni.checkIsSoterEnrolledInDevice({
			checkAuthMode: type,
			success(res) {
				res.isEnrolled && uni.startSoterAuthentication({
					requestAuthModes: [type],
					challenge: '123456',
					authContent: '生物解锁',
					success(res) {
						console.log(res,'成功回调','执行相关逻辑');
					}
				})
			}
		})
	}
</script>

<style lang="scss" scoped>
	
</style>

效果展示:

相关推荐
米粒宝的爸爸18 小时前
uniapp在app端,在导航栏设置自定义按钮
uni-app
dssxyz18 小时前
uniapp打包微信小程序主包过大问题_uniapp 微信小程序时主包太大和vendor.js过大
javascript·微信小程序·uni-app
xw519 小时前
我犯了错,我于是为我的uni-app项目引入环境标志
前端·uni-app
!win !19 小时前
被老板怼后,我为uni-app项目引入环境标志
前端·小程序·uni-app
颜渊呐1 天前
uniapp中APPwebview与网页的双向通信
前端·uni-app
白杨木影子被拉长1 天前
多状态映射不同样式(scss语法)
vue.js·uni-app
一念杂记1 天前
免费开源!微信小程序商城源码,快速搭建你的线上商城系统!
微信小程序·uni-app
aklry1 天前
uniapp三步完成生成一维码图片
uni-app
雪芽蓝域zzs2 天前
uniapp 国密sm2加密
uni-app
打不着的大喇叭2 天前
uniapp的光标跟随和打字机效果
前端·javascript·uni-app