跳转到主要内容

Liveness(生物特征自拍)

通过内置活体验证进行生物特征自拍采集。SDK 通过 SmartFrames 引导用户,直至获取生物特征有效的图像帧,并以 Base64 + JWT 形式返回图像。

能力

此采集类型使用 Liveness 能力。有关 Liveness 工作原理的概念性概述,请参阅 Liveness 能力页面。

工作原理

SDK 管理完整的采集会话:

  1. 以 SmartFrame 叠加层打开摄像头。
  2. 引导用户将面部定位在框架内。
  3. 验证活体——仅当用户实际在场时,会话才会完成。
  4. 返回包含 base64encrypted(JWT)的 SelfieResult(别名 ResultCamera)对象。
摄像头模式(智能采集)

SDK 默认启用智能取景自动采集。在构建器中按如下方式配置摄像头模式:

unicoCheck.setSmartFrame(true)
unicoCheck.setAutoCapture(true)
启动活体采集
步骤 1 — 实现 AcessoBioManagerDelegate

AcessoBioManagerDelegate 负责处理 SDK 生命周期回调。实现以下四个必须的方法:

方法调用时机
onErrorAcessoBioManager(error)SDK 操作过程中发生错误
onUserClosedCameraManually()用户手动关闭了摄像头
onSystemClosedCameraTimeoutSession()达到 40 秒会话时间限制
onSystemChangedTypeCameraTimeoutFaceInference()13 秒内未检测到人脸 — 切换为手动捕获
class ViewController: UIViewController, AcessoBioManagerDelegate {
var unicoCheck: AcessoBioManager!

override func viewDidLoad() {
super.viewDidLoad()
unicoCheck = AcessoBioManager(viewController: self)
}

func onErrorAcessoBioManager(_ error: ErrorBio!) { }
func onUserClosedCameraManually() { }
func onSystemClosedCameraTimeoutSession() { }
func onSystemChangedTypeCameraTimeoutFaceInference() { }
}
必须实现的委托方法

上述四个委托方法必须在您的项目中创建(即使不包含任何逻辑)。否则,项目将无法成功编译。

步骤 2 — 实现 SelfieCameraDelegateAcessoBioSelfieDelegate

这些委托处理自拍采集结果回调:

方法描述
onSuccessSelfie(result)采集成功——返回包含 base64(预览)和 encrypted(用于 API 的 JWT)的 SelfieResult
onErrorSelfie(errorBio)采集失败——返回包含代码和描述的 ErrorBio
Token 过期

生成 encrypted 与将其提交至 API 之间的时间间隔不得超过 10 分钟

class ViewController: UIViewController, AcessoBioManagerDelegate,
SelfieCameraDelegate, AcessoBioSelfieDelegate {

func onSuccessSelfie(_ result: SelfieResult!) { }
func onErrorSelfie(_ errorBio: ErrorBio!) { }
}
步骤 3 — 调用 prepareSelfieCameraopen

调用 prepareSelfieCamera 并传入 SDK 配置。摄像头就绪后,onCameraReady 事件将触发,并携带 AcessoBioCameraOpenerDelegate——通过 open() 方法打开摄像头:

  • onCameraReady(cameraOpener) — 摄像头已就绪;调用 open(self)
  • onCameraFailed(message) — 摄像头准备失败(ErrorPrepareErrorBio 的扩展)。
@IBAction func openCamera(_ sender: Any) {
unicoCheck.build().prepareSelfieCamera(self, config: YourUnicoConfigClass())
}

func onCameraReady(_ cameraOpener: AcessoBioCameraOpenerDelegate!) {
cameraOpener.open(self)
}

func onCameraFailed(_ message: ErrorPrepare!) { }
监控数据收集

prepareSelfieCamera 方法提供一个重载,通过 PrepareInfo 接受元数据,以协助识别用户会话和流程:

  • externalUserId(String,必填)——您系统中的用户标识符。传输前自动使用 SHA-256 进行哈希处理。
  • useCase(String,可选)——当前运行的上下文或流程标识符(例如 "account_opening""password_recovery")。以明文传输。
let prepareInfo = PrepareInfo(
externalUserId: "external_user_id",
useCase: "use_case"
)
unicoCheck.build().prepareSelfieCamera(
self,
config: YourUnicoConfigClass(),
prepareInfo: prepareInfo
)

有关完整的结果处理,请参阅接收结果