• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.userIAM.faceAuth (人脸认证)(系统接口)
2
3<!--Kit: User Authentication Kit-->
4<!--Subsystem: UserIAM-->
5<!--Owner: @WALL_EYE-->
6<!--Designer: @lichangting518-->
7<!--Tester: @jane_lz-->
8<!--Adviser: @zengyawen-->
9
10提供人脸录入相关接口。
11
12> **说明:**
13>
14> - 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
15>
16> - 本模块为系统接口。
17
18## 导入模块
19
20```ts
21import { faceAuth } from '@kit.UserAuthenticationKit';
22```
23
24## FaceAuthManager
25
26人脸认证管理器对象。
27
28### constructor
29
30constructor()
31
32表示获取人脸认证管理器对象。
33
34**系统能力:** SystemCapability.UserIAM.UserAuth.FaceAuth
35
36**系统接口:** 此接口为系统接口。
37
38**返回值:**
39
40| 类型                   | 说明                 |
41| ---------------------- | -------------------- |
42| [FaceAuthManager](#faceauthmanager) | 人脸认证管理器对象。 |
43
44**示例:**
45
46```ts
47import { faceAuth } from '@kit.UserAuthenticationKit';
48
49let faceAuthManager = new faceAuth.FaceAuthManager();
50```
51
52### setSurfaceId
53
54setSurfaceId(surfaceId: string): void;
55
56该接口仅用于在录入人脸时,设置人脸预览界面 [XComponent](../apis-arkui/arkui-ts/ts-basic-components-xcomponent.md#getxcomponentsurfaceid9) 持有 Surface 的 ID,需要配合[人脸录入接口](../apis-basic-services-kit/js-apis-osAccount-sys.md#addcredential8)来使用。
57
58**系统能力:** SystemCapability.UserIAM.UserAuth.FaceAuth
59
60**系统接口:** 此接口为系统接口。
61
62**需要权限:** ohos.permission.MANAGE_USER_IDM
63
64**参数:**
65
66| 参数名         | 类型                               | 必填 | 说明                       |
67| -------------- | ---------------------------------- | ---- | -------------------------- |
68| surfaceId       | string     | 是   | [XComponent](../apis-arkui/arkui-ts/ts-basic-components-xcomponent.md#getxcomponentsurfaceid9) 持有 Surface 的 ID。 |
69
70以下错误码的详细介绍请参见[用户认证错误码](errorcode-useriam.md)。
71
72**错误码:**
73
74| 错误码ID | 错误信息 |
75| -------- | ------- |
76| 201 | Permission denied. |
77| 202 | Permission denied. Called by non-system application. |
78| 12700001 | The service is unavailable. |
79
80**示例:**
81
82```ts
83import { faceAuth } from '@kit.UserAuthenticationKit';
84import { BusinessError } from '@kit.BasicServicesKit';
85
86// 该surfaceId应该从XComponent控件获取,此处仅用作示例。
87let surfaceId = '123456';
88let manager = new faceAuth.FaceAuthManager();
89try {
90  manager.setSurfaceId(surfaceId);
91  console.info('set surface id success');
92} catch (error) {
93  const err: BusinessError = error as BusinessError;
94  console.error(`set surface id failed, Code is ${err?.code}, message is ${err?.message}`);
95}
96```
97