uni-app plus.fingerprint在iphone下FACE ID的解锁问题
uni-app plus.fingerprint在iphone下FACE ID的解锁问题
| 开发环境 | 版本号 | 项目创建方式 |
|---|---|---|
| HBuilderX | 3.2.16 |
产品分类:HTML5+
手机系统:iOS
手机系统版本号:iOS 14
手机厂商:苹果
手机机型:iphone X
打包方式:云端
示例代码:
```javascript
plus.fingerprint.authenticate(function(){
plus.nativeUI.closeWaiting();//兼容Android平台关闭等待框
alert('指纹识别成功');
}, function(e){
switch(e.code) {
case e.AUTHENTICATE_MISMATCH:
plus.nativeUI.toast('指纹匹配失败,请重新输入');
break;
case e.AUTHENTICATE_OVERLIMIT:
plus.nativeUI.closeWaiting();//兼容Android平台关闭等待框
plus.nativeUI.alert('指纹识别失败次数超出限制,请使用其它方式进行认证');
break;
default:
plus.nativeUI.closeWaiting();//兼容Android平台关闭等待框
plus.nativeUI.alert('指纹识别失败('+e.code+'),请重试');
break;
}
});
错误代码1,不支持。iphoneX是FACE ID解锁,没指纹的。
又测试了Native.js方式:
function authenticate(){
var LAContext = plus.ios.importClass('LAContext');
var lacontext = plus.ios.newObject("LAContext");
var isSupport = lacontext.canEvaluatePolicyerror(1, null); //返回是否支持指纹识别
console.log('isSupport:'+isSupport);
if(isSupport){
lacontext.evaluatePolicylocalizedReasonreply(2, '请校验指纹A', function (success){
console.log('success:'+success);
});
}
}
用试上面的代码测试,FACE ID能正常工作。
但是lacontext.evaluatePolicylocalizedReasonreply(2, '请校验指纹A', function (redate){ console.log('redate:'+redate); });
这段回调拿不到实别的结果,打印 redate:undefined
操作步骤:
错误代码1
预期结果:
错误代码1
实际结果:
错误代码1
bug描述:
plus.fingerprint.authenticate(function(){
plus.nativeUI.closeWaiting();//兼容Android平台关闭等待框
alert('指纹识别成功');
}, function(e){
switch(e.code) {
case e.AUTHENTICATE_MISMATCH:
plus.nativeUI.toast('指纹匹配失败,请重新输入');
break;
case e.AUTHENTICATE_OVERLIMIT:
plus.nativeUI.closeWaiting();//兼容Android平台关闭等待框
plus.nativeUI.alert('指纹识别失败次数超出限制,请使用其它方式进行认证');
break;
default:
plus.nativeUI.closeWaiting();//兼容Android平台关闭等待框
plus.nativeUI.alert('指纹识别失败('+e.code+'),请重试');
break;
}
});
错误代码1,不支持。iphoneX是FACE ID解锁,没指纹的。
又测试了Native.js方式:
function authenticate(){
var LAContext = plus.ios.importClass('LAContext');
var lacontext = plus.ios.newObject("LAContext");
var isSupport = lacontext.canEvaluatePolicyerror(1, null); //返回是否支持指纹识别
console.log('isSupport:'+isSupport);
if(isSupport){
lacontext.evaluatePolicylocalizedReasonreply(2, '请校验指纹A', function (success){
console.log('success:'+success);
});
}
}
用试上面的代码测试,FACE ID能正常工作。
但是lacontext.evaluatePolicylocalizedReasonreply(2, '请校验指纹A', function (redate){ console.log('redate:'+redate); });
这段回调拿不到实别的结果,打印 redate:undefined
更多关于uni-app plus.fingerprint在iphone下FACE ID的解锁问题的实战教程也可以访问 https://www.itying.com/category-93-b0.html
更多关于uni-app plus.fingerprint在iphone下FACE ID的解锁问题的实战教程也可以访问 https://www.itying.com/category-93-b0.html
根据你的描述,问题在于 plus.fingerprint 模块在 iOS 设备上仅支持 Touch ID(指纹识别),不支持 Face ID。因此,在 iPhone X 这类仅配备 Face ID 的设备上调用 plus.fingerprint.authenticate 会返回错误代码 1(即不支持)。这是 plus.fingerprint 模块本身的限制,与设备硬件无关。
你尝试的 Native.js 方案是正确的方向,因为直接调用 iOS 原生接口可以同时支持 Touch ID 和 Face ID。但回调中 redate 为 undefined 是因为 evaluatePolicy:localizedReason:reply: 方法的回调函数参数顺序和类型需要正确处理。以下是修正后的代码示例:
function authenticate() {
var LAContext = plus.ios.importClass('LAContext');
var lacontext = plus.ios.newObject('LAContext');
var errorRef = plus.ios.newObject('NSErrorPtr');
var isSupport = lacontext.canEvaluatePolicyError(1, errorRef); // 1 对应 LAPolicyDeviceOwnerAuthenticationWithBiometrics
console.log('isSupport:' + isSupport);
if (isSupport) {
lacontext.evaluatePolicyLocalizedReasonReply(1, '请进行身份验证', function(success, error) {
plus.ios.deleteObject(errorRef);
if (success) {
console.log('验证成功');
// 处理成功逻辑
} else {
var errorCode = error ? plus.ios.invoke(error, 'code') : -1;
console.log('验证失败,错误代码:' + errorCode);
// 处理失败逻辑
}
});
} else {
console.log('设备不支持生物识别');
}
}

