准备工作:
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>
效果展示:
