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>

效果展示:

相关推荐
蛋 卷14 小时前
uni-app页面怎么设计更美观
uni-app
Dashingl14 小时前
uni-app AES 加密
android·javascript·uni-app
HWT?14 小时前
uni-app前端处理瀑布流V2写法
uni-app
专业系统开发老赵14 小时前
[特殊字符]《多商户家政系统技术解析:SpringBoot+MyBatisPlus+UniApp高效实战指南》
spring boot·后端·uni-app
wocwin17 小时前
uniapp微信小程序封装navbar组件
微信小程序·uni-app·vue3·组件封装·navbar
承前智1 天前
基于Hbuilder X的uni-app连接OneNET云平台及AI交互 实战指南(三)——命令下发
uni-app·交互
十八朵郁金香1 天前
【Uni-App】嵌入悬浮球全局组件的详细教程和防踩坑点
uni-app
修复bug1 天前
Uniapp自定义TabBar组件全封装实践与疑难问题解决方案
前端·javascript·vue.js·uni-app·开源
Kx…………1 天前
Uni-app入门到精通:subPackages节点为小程序的分包加载配置
前端·学习·小程序·uni-app
冰凉小脚2 天前
uniapp 自定义展开/收起组件(适配H5、微信小程序等)
微信小程序·小程序·uni-app