### Install SDK using CocoaPods commands Source: https://context7.com/yidun/nteslivedetect/llms.txt Update your local pod repository and install the SDK, or use the --repo-update flag if you haven't updated recently. ```bash # 安装命令 pod repo update pod install # 若未执行 pod repo update,可使用 pod install --repo-update ``` -------------------------------- ### Start Live Detection with Failover Configuration Source: https://context7.com/yidun/nteslivedetect/llms.txt Initiates live detection with support for multiple domain configurations to enable failover, enhancing service availability. ```APIDOC ## POST /api/startLiveDetect/configURL ### Description Starts the live detection process and supports configuring multiple domains for failover. If the primary domain request fails, it automatically attempts the next domain. ### Method POST ### Endpoint /api/startLiveDetect/configURL ### Parameters #### Request Body - **businessID** (string) - Required - The business ID obtained from the Yidun console. - **configURLs** (array of strings) - Required - An array of domain URLs for failover. - **actionsHandler** (function) - Required - Callback function to handle action sequences. - **checkingHandler** (function) - Required - Callback function to indicate cloud verification is in progress. - **completionHandler** (function) - Required - Callback function to handle the final detection result. ### Request Example ```objectivec NSString *businessID = @"your_business_id"; NSArray *configURLs = @[ @"https://c.dun.163.com", // Primary domain @"https://c-backup.dun.163.com" // Backup domain ]; [self.detectManager startLiveDetectWithBusinessID:businessID configURL:configURLs actionsHandler:^(NSDictionary *params) { // Handle actions } checkingHandler:^{ // Handle checking } completionHandler:^(NTESLDStatus status, NSDictionary *params) { // Handle completion }]; ``` ### Response #### Success Response (200) - **status** (NTESLDStatus) - The status of the live detection. - **params** (NSDictionary) - Additional parameters, including a 'token' on success. #### Response Example ```json { "status": "NTESLDCheckPass", "params": { "token": "your_detection_token" } } ``` ``` -------------------------------- ### Start Live Detection Source: https://context7.com/yidun/nteslivedetect/llms.txt Initiates the live detection process with a given business ID. It handles random action sequences, cloud verification, and returns the final result. ```APIDOC ## POST /api/startLiveDetect ### Description Starts the live detection process. Requires a business ID and multiple callback handlers for actions, checking, and completion. ### Method POST ### Endpoint /api/startLiveDetect ### Parameters #### Request Body - **businessID** (string) - Required - The business ID obtained from the Yidun console. - **actionsHandler** (function) - Required - Callback function to handle action sequences. - **checkingHandler** (function) - Required - Callback function to indicate cloud verification is in progress. - **completionHandler** (function) - Required - Callback function to handle the final detection result. ### Request Example ```objectivec NSString *businessID = @"your_business_id"; [self.detectManager startLiveDetectWithBusinessID:businessID actionsHandler:^(NSDictionary *params) { // Handle actions } checkingHandler:^{ // Handle checking } completionHandler:^(NTESLDStatus status, NSDictionary *params) { // Handle completion }]; ``` ### Response #### Success Response (200) - **status** (NTESLDStatus) - The status of the live detection. - **params** (NSDictionary) - Additional parameters, including a 'token' on success. #### Response Example ```json { "status": "NTESLDCheckPass", "params": { "token": "your_detection_token" } } ``` #### Error Handling - **NTESLDCheckNotPass**: Live detection failed. - **NTESLDOperationTimeout**: Operation timed out. - **NTESLDGetConfTimeout**: Failed to get configuration. - **NTESLDOnlineCheckTimeout**: Cloud verification timed out. - **NTESLDOnlineUploadFailure**: Image upload failed. - **NTESLDNonGateway**: Network not connected. - **NTESLDSDKError**: SDK internal error. - **NTESLDCameraNotAvailable**: Camera permission not granted. - **NTESLDCameraNotSupport**: Camera is not available. ``` -------------------------------- ### Start Live Detection with Business ID and Config URLs Source: https://context7.com/yidun/nteslivedetect/llms.txt Initiates live detection with support for multiple domain configurations to enable failover. If the primary domain request fails, the SDK automatically attempts to use the backup domain, improving service availability. ```Objective-C - (void)startDetectionWithFailover { NSString *businessID = @"your_business_id"; // 配置多个域名,实现域名重试机制 NSArray *configURLs = @[ @"https://c.dun.163.com", // 主域名 @"https://c-backup.dun.163.com" // 备用域名 ]; [self.detectManager startLiveDetectWithBusinessID:businessID configURL:configURLs actionsHandler:^(NSDictionary *params) { NSLog(@"动作序列: %@", params); } checkingHandler:^{ NSLog(@"云端验证中..."); } completionHandler:^(NTESLDStatus status, NSDictionary *params) { [self handleDetectionResult:status params:params]; }]; } ``` -------------------------------- ### Start Live Detection with Completion Handler Source: https://context7.com/yidun/nteslivedetect/llms.txt Initiates the live detection process and provides a completion handler to process the results. Ensure the UI updates are on the main thread. ```objective-c weakSelf.statusLabel.text = @"正在验证..."; [weakSelf.loadingIndicator startAnimating]; }); } completionHandler:^(NTESLDStatus status, NSDictionary *params) { dispatch_async(dispatch_get_main_queue(), ^{ [weakSelf.loadingIndicator stopAnimating]; [weakSelf handleResult:status params:params]; }); }]; ``` -------------------------------- ### Get Action Prompt String Source: https://context7.com/yidun/nteslivedetect/llms.txt Returns a user-facing prompt string based on the integer code representing a required action. ```objective-c - (NSString *)promptForAction:(NSInteger)action { NSArray *prompts = @[@"请保持正面", @"请向右转头", @"请向左转头", @"请张嘴", @"请眨眼"]; if (action == -1) return @"请将面部置于框内"; return action < prompts.count ? prompts[action] : @"请完成动作"; } ``` -------------------------------- ### Installation with CocoaPods Source: https://context7.com/yidun/nteslivedetect/llms.txt Integrate the NTESLiveDetect SDK into your iOS project using CocoaPods. You can install the latest version or a specific version. ```APIDOC ## Installation with CocoaPods Use the CocoaPods package manager to install the NTESLiveDetect SDK. You can specify a version or use the latest. ### Podfile Configuration ```ruby # Install the latest SDK version pod 'NTESLiveDetect' # Install a specific version pod 'NTESLiveDetect', '~> 3.2.11' # For modular integration pod 'NTESLiveDetect/Basic' # Core liveness detection module pod 'NTESLiveDetect/Nenn' # Neural network module ``` ### Installation Commands ```bash # Update your local pod repository pod repo update pod install # If you skipped `pod repo update`, use: pod install --repo-update ``` ``` -------------------------------- ### Start Live Detection with Business ID Source: https://context7.com/yidun/nteslivedetect/llms.txt Initiates the live detection process using a business ID. Requires handlers for actions, checking, and completion. Ensure the business ID is obtained from the Yidun console. ```Objective-C - (void)startDetection { NSString *businessID = @"your_business_id"; // 从易盾控制台获取 [self.detectManager startLiveDetectWithBusinessID:businessID actionsHandler:^(NSDictionary *params) { // 获取动作序列码 // 动作状态:0-正面,1-右转,2-左转,3-张嘴,4-眨眼 NSLog(@"动作序列: %@", params); NSArray *actions = params[@"actions"]; for (NSNumber *action in actions) { switch (action.integerValue) { case 0: NSLog(@"请保持正面"); break; case 1: NSLog(@"请向右转头"); break; case 2: NSLog(@"请向左转头"); break; case 3: NSLog(@"请张嘴"); break; case 4: NSLog(@"请眨眼"); break; } } } checkingHandler:^{ // 正在进行云端检测 NSLog(@"正在验证,请稍候..."); [self showLoadingIndicator]; } completionHandler:^(NTESLDStatus status, NSDictionary *params) { // 处理检测结果 [self hideLoadingIndicator]; [self handleDetectionResult:status params:params]; }]; } - (void)handleDetectionResult:(NTESLDStatus)status params:(NSDictionary *)params { switch (status) { case NTESLDCheckPass: NSLog(@"活体检测通过"); NSLog(@"Token: %@", params[@"token"]); // 将 token 发送至服务端进行二次校验 [self verifyTokenWithServer:params[@"token"]]; break; case NTESLDCheckNotPass: NSLog(@"活体检测不通过"); [self showAlert:@"检测失败" message:@"请确保是本人操作"]; break; case NTESLDOperationTimeout: NSLog(@"操作超时"); [self showAlert:@"超时" message:@"未在规定时间内完成动作"]; break; case NTESLDGetConfTimeout: NSLog(@"获取配置超时"); [self showAlert:@"网络错误" message:@"获取检测配置失败"]; break; case NTESLDOnlineCheckTimeout: NSLog(@"云端检测超时"); [self showAlert:@"网络错误" message:@"云端验证超时"]; break; case NTESLDOnlineUploadFailure: NSLog(@"上传图片失败"); [self showAlert:@"上传失败" message:@"图片上传失败,请重试"]; break; case NTESLDNonGateway: NSLog(@"网络未连接"); [self showAlert:@"网络错误" message:@"请检查网络连接"]; break; case NTESLDSDKError: NSLog(@"SDK 内部错误"); [self showAlert:@"系统错误" message:@"检测服务异常"]; break; case NTESLDCameraNotAvailable: NSLog(@"未获取相机权限"); [self showAlert:@"权限错误" message:@"请在设置中开启相机权限"]; break; case NTESLDCameraNotSupport: NSLog(@"相机不可用"); [self showAlert:@"设备错误" message:@"相机不可用"]; break; } // 停止检测 [self.detectManager stopLiveDetect]; } ``` -------------------------------- ### Get Exception Message String Source: https://context7.com/yidun/nteslivedetect/llms.txt Returns a user-facing message string based on the integer code representing a detection exception. ```objective-c - (NSString *)messageForException:(NSInteger)code { NSDictionary *messages = @{ @1: @"请保持面部在框内", @2: @"光线过暗,请移至明亮处", @3: @"光线过亮,请避免强光", @4: @"请保持手机稳定", @5: @"请确保只有一人在画面中", @6: @"请靠近一些", @7: @"请远离一些" }; return messages[@(code)] ?: @"检测中..."; } ``` -------------------------------- ### Get SDK Version for Logging Source: https://context7.com/yidun/nteslivedetect/llms.txt Retrieve the current SDK version using `getSDKVersion`. This is useful for logging purposes, troubleshooting, and version compatibility checks. ```Objective-C - (void)logSDKInfo { NSString *version = [self.detectManager getSDKVersion]; NSLog(@"NTESLiveDetect SDK Version: %@", version); // 输出示例: NTESLiveDetect SDK Version: 3.2.11 } ``` -------------------------------- ### 实现活体检测视图控制器 Source: https://context7.com/yidun/nteslivedetect/llms.txt 包含 UI 初始化、摄像头权限检查及检测管理器配置的完整视图控制器实现。需确保已导入 NTESLiveDetect 和 AVFoundation 框架。 ```objectivec #import #import @interface LiveDetectViewController : UIViewController @property (nonatomic, strong) NTESLiveDetectManager *detectManager; @property (nonatomic, strong) UIImageView *cameraView; @property (nonatomic, strong) UILabel *statusLabel; @property (nonatomic, strong) UIActivityIndicatorView *loadingIndicator; @property (nonatomic, copy) void (^completionBlock)(BOOL success, NSString *token); @end @implementation LiveDetectViewController - (void)viewDidLoad { [super viewDidLoad]; [self setupUI]; [self setupNotifications]; } - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; [self checkCameraPermissionAndStart]; } - (void)setupUI { self.view.backgroundColor = [UIColor blackColor]; // 摄像头预览 (3:4 比例) CGFloat width = self.view.bounds.size.width * 0.85; CGFloat height = width * 4.0 / 3.0; self.cameraView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, width, height)]; self.cameraView.center = CGPointMake(self.view.center.x, self.view.center.y - 50); self.cameraView.layer.cornerRadius = 12; self.cameraView.layer.masksToBounds = YES; self.cameraView.layer.borderColor = [UIColor whiteColor].CGColor; self.cameraView.layer.borderWidth = 2; [self.view addSubview:self.cameraView]; // 状态提示 self.statusLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, CGRectGetMaxY(self.cameraView.frame) + 30, self.view.bounds.size.width - 40, 60)]; self.statusLabel.textColor = [UIColor whiteColor]; self.statusLabel.textAlignment = NSTextAlignmentCenter; self.statusLabel.numberOfLines = 2; self.statusLabel.font = [UIFont systemFontOfSize:18 weight:UIFontWeightMedium]; self.statusLabel.text = @"准备开始检测..."; [self.view addSubview:self.statusLabel]; // 加载指示器 self.loadingIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleLarge]; self.loadingIndicator.color = [UIColor whiteColor]; self.loadingIndicator.center = self.view.center; self.loadingIndicator.hidesWhenStopped = YES; [self.view addSubview:self.loadingIndicator]; // 取消按钮 UIButton *cancelButton = [UIButton buttonWithType:UIButtonTypeSystem]; cancelButton.frame = CGRectMake(20, self.view.bounds.size.height - 100, self.view.bounds.size.width - 40, 50); [cancelButton setTitle:@"取消" forState:UIControlStateNormal]; [cancelButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; cancelButton.titleLabel.font = [UIFont systemFontOfSize:17]; [cancelButton addTarget:self action:@selector(cancelDetection) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:cancelButton]; } - (void)setupNotifications { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onStatusChange:) name:NTESLDNotificationStatusChange object:nil]; } - (void)checkCameraPermissionAndStart { AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo]; switch (status) { case AVAuthorizationStatusAuthorized: [self initializeAndStartDetection]; break; case AVAuthorizationStatusNotDetermined: [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) { dispatch_async(dispatch_get_main_queue(), ^{ if (granted) { [self initializeAndStartDetection]; } else { [self showPermissionDeniedAlert]; } }); }]; break; default: [self showPermissionDeniedAlert]; break; } } - (void)initializeAndStartDetection { // 初始化检测管理器 self.detectManager = [[NTESLiveDetectManager alloc] initWithImageView:self.cameraView withDetectSensit:NTESSensitNormal]; // 配置参数 [self.detectManager setTimeoutInterval:30.0]; [self.detectManager setShakeThreshold:0.05]; [self.detectManager setAllowMultipleFace:NO]; [self.detectManager setMinFacePercentage:7]; [self.detectManager setMaxFacePercentage:60]; // 开始检测 __weak typeof(self) weakSelf = self; [self.detectManager startLiveDetectWithBusinessID:@"your_business_id" actionsHandler:^(NSDictionary *params) { dispatch_async(dispatch_get_main_queue(), ^{ weakSelf.statusLabel.text = @"请按照提示完成动作"; }); } checkingHandler:^{ dispatch_async(dispatch_get_main_queue(), ^{ ``` -------------------------------- ### Configure Detection Settings in Objective-C Source: https://context7.com/yidun/nteslivedetect/llms.txt Customize liveness detection behavior by setting parameters such as timeout interval, shake threshold, multi-face allowance, and face percentage range. Adjust these values to fine-tune the detection sensitivity and user experience. ```objectivec // 配置检测参数 - (void)configureDetectionSettings { // 设置超时时间(10-120秒,默认30秒) [self.detectManager setTimeoutInterval:45.0]; // 设置设备抖动检测灵敏度(0.01-0.1,默认0.05) // 值越小越敏感,容易触发"请勿抖动手机"提示 [self.detectManager setShakeThreshold:0.05]; // 是否允许多人脸(默认 NO) [self.detectManager setAllowMultipleFace:NO]; // 设置人脸占比范围(0-100) // 人脸在画面中占比过小会提示"距离过远",过大会提示"距离过近" [self.detectManager setMinFacePercentage:7]; // 默认 7% [self.detectManager setMaxFacePercentage:60]; // 默认 60% } ``` -------------------------------- ### Monitor Live Detect Status with NSNotificationCenter Source: https://context7.com/yidun/nteslivedetect/llms.txt Set up an observer to receive notifications for real-time action detection status and exceptions. This is useful for updating the UI to inform the user about the current operation state. Ensure to remove the observer in dealloc. ```Objective-C - (void)setupNotificationObserver { // 注册动作状态监听 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleStatusChange:) name:NTESLDNotificationStatusChange object:nil]; } - (void)handleStatusChange:(NSNotification *)notification { // 获取动作状态 NSDictionary *actionInfo = [notification.userInfo objectForKey:@"action"]; if (actionInfo) { // key: 当前动作 (0-正面, 1-右转, 2-左转, 3-张嘴, 4-眨眼, -1-未检测到完整人脸) // value: 完成状态 (NO-未完成, YES-已完成) for (NSNumber *actionKey in actionInfo.allKeys) { BOOL completed = [actionInfo[actionKey] boolValue]; NSString *actionName = [self actionNameForKey:actionKey.integerValue]; if (completed) { [self updateUI:@"✓ %@ 完成" actionName:actionName]; } else { [self updateUI:@"请 %@" actionName:actionName]; } } } // 获取异常状态 NSString *exception = [notification.userInfo objectForKey:@"exception"]; if (exception) { // 异常码:1-保持面部在框内, 2-环境光线过暗, 3-环境光线过亮, // 4-请勿抖动手机, 5-多人脸, 6-距离过远, 7-距离过近 NSString *message = [self exceptionMessageForCode:exception.integerValue]; [self showWarningMessage:message]; } } - (NSString *)actionNameForKey:(NSInteger)key { switch (key) { case 0: return @"保持正面"; case 1: return @"向右转头"; case 2: return @"向左转头"; case 3: return @"张嘴"; case 4: return @"眨眼"; case -1: return @"将面部置于框内"; default: return @"未知动作"; } } - (NSString *)exceptionMessageForCode:(NSInteger)code { switch (code) { case 1: return @"请保持面部在框内"; case 2: return @"环境光线过暗,请移至明亮处"; case 3: return @"环境光线过亮,请避免强光"; case 4: return @"请勿抖动手机"; case 5: return @"检测到多张人脸,请确保只有一人"; case 6: return @"距离过远,请靠近"; case 7: return @"距离过近,请远离"; default: return @"检测异常"; } } - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self name:NTESLDNotificationStatusChange object:nil]; } ``` -------------------------------- ### Configure Detection Parameters Source: https://context7.com/yidun/nteslivedetect/llms.txt Customize the liveness detection behavior by setting parameters such as timeout, shake threshold, and face detection range. ```APIDOC ## Configure Detection Parameters Customize the liveness detection behavior using various configuration methods. This includes setting timeouts, shake sensitivity, and face detection thresholds. ### Objective-C Example ```objectivec // Configure detection settings - (void)configureDetectionSettings { // Set timeout interval (10-120 seconds, default 30 seconds) [self.detectManager setTimeoutInterval:45.0]; // Set device shake detection sensitivity (0.01-0.1, default 0.05) // Lower values increase sensitivity, potentially triggering "Do not shake your phone" warnings more easily. [self.detectManager setShakeThreshold:0.05]; // Allow multiple faces (default NO) [self.detectManager setAllowMultipleFace:NO]; // Set face percentage range (0-100) // If the face occupies too little screen space, it prompts "Too far". If too much, "Too close". [self.detectManager setMinFacePercentage:7]; // Default 7% [self.detectManager setMaxFacePercentage:60]; // Default 60% } ``` ``` -------------------------------- ### Initialize Detection Manager Source: https://context7.com/yidun/nteslivedetect/llms.txt Initialize the NTESLiveDetectManager, providing a UIImageView for camera preview and setting the detection sensitivity. ```APIDOC ## Initialize Detection Manager Create an instance of the liveness detection manager. This requires a `UIImageView` for camera display (must have a 3:4 aspect ratio) and a sensitivity level. ### Sensitivity Levels - `NTESSensitEasy`: Easy mode, easier to pass. - `NTESSensitNormal`: Normal mode (default). - `NTESSensitHard`: Hard mode, strict verification. ### Objective-C Example ```objectivec #import @interface ViewController () @property (nonatomic, strong) NTESLiveDetectManager *detectManager; @property (nonatomic, strong) UIImageView *cameraImageView; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Create camera preview view (must be 3:4 aspect ratio) self.cameraImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 100, 300, 400)]; self.cameraImageView.center = CGPointMake(self.view.center.x, self.cameraImageView.center.y); [self.view addSubview:self.cameraImageView]; // Initialize detection manager with default sensitivity self.detectManager = [[NTESLiveDetectManager alloc] initWithImageView:self.cameraImageView withDetectSensit:NTESSensitNormal]; // Optional: Initialize with custom resource path // NSString *bundlePath = [[NSBundle mainBundle] pathForResource:@"NTESLiveDetectBundle" ofType:@"bundle"]; // self.detectManager = [[NTESLiveDetectManager alloc] initWithImageView:self.cameraImageView // withDetectBundlePath:bundlePath // withDetectSensit:NTESSensitNormal]; } @end ``` ``` -------------------------------- ### Show Camera Permission Denied Alert Source: https://context7.com/yidun/nteslivedetect/llms.txt Presents an alert to the user indicating that camera permission is required and provides an option to navigate to the app's settings. ```objective-c - (void)showPermissionDeniedAlert { UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"需要相机权限" message:@"请在设置中开启相机权限以使用活体检测功能" preferredStyle:UIAlertControllerStyleAlert]; [alert addAction:[UIAlertAction actionWithTitle:@"去设置" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString] options:@{} completionHandler:nil]; }]]; [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { [self dismissViewControllerAnimated:YES completion:nil]; }]]; [self presentViewController:alert animated:YES completion:nil]; } ``` -------------------------------- ### Integrate NTESLiveDetect via CocoaPods Source: https://github.com/yidun/nteslivedetect/blob/master/README.md Add these lines to your Podfile to include the NTESLiveDetect SDK in your project. ```ruby # 以下两种版本选择方式示例 # 集成最新版SDK: pod 'NTESLiveDetect' # 集成指定SDK,具体版本号可先执行 pod search NTESLiveDetect,根据返回的版本信息自行决定: pod 'NTESLiveDetect', '~> 2.2.5' ``` -------------------------------- ### Initialize NTESLiveDetectManager in Objective-C Source: https://context7.com/yidun/nteslivedetect/llms.txt Initialize the NTESLiveDetectManager with a UIImageView for camera preview and a detection sensitivity level. Ensure the UIImageView has a 3:4 aspect ratio. You can also specify a custom bundle path for resources. ```objectivec #import @interface ViewController () @property (nonatomic, strong) NTESLiveDetectManager *detectManager; @property (nonatomic, strong) UIImageView *cameraImageView; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // 创建摄像头预览视图,宽高比必须为 3:4 self.cameraImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 100, 300, 400)]; self.cameraImageView.center = CGPointMake(self.view.center.x, self.cameraImageView.center.y); [self.view addSubview:self.cameraImageView]; // 初始化检测管理器,使用默认灵敏度 self.detectManager = [[NTESLiveDetectManager alloc] initWithImageView:self.cameraImageView withDetectSensit:NTESSensitNormal]; // 可选:使用自定义资源路径初始化 // NSString *bundlePath = [[NSBundle mainBundle] pathForResource:@ ``` -------------------------------- ### Handle Detection Results Source: https://context7.com/yidun/nteslivedetect/llms.txt Processes the final result of the live detection. If successful, it extracts a token and calls the completion block. Otherwise, it presents an alert for retry or cancellation. ```objective-c - (void)handleResult:(NTESLDStatus)status params:(NSDictionary *)params { [self.detectManager stopLiveDetect]; if (status == NTESLDCheckPass) { NSString *token = params[@"token"]; if (self.completionBlock) { self.completionBlock(YES, token); } [self dismissViewControllerAnimated:YES completion:nil]; } else { NSString *message = @"检测失败,请重试"; if (status == NTESLDOperationTimeout) message = @"操作超时"; if (status == NTESLDNonGateway) message = @"网络连接失败"; UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:message preferredStyle:UIAlertControllerStyleAlert]; [alert addAction:[UIAlertAction actionWithTitle:@"重试" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { [self initializeAndStartDetection]; }]]; [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { if (self.completionBlock) { self.completionBlock(NO, nil); } [self dismissViewControllerAnimated:YES completion:nil]; }]]; [self presentViewController:alert animated:YES completion:nil]; } } ``` -------------------------------- ### Integrate NTESLiveDetect SDK with CocoaPods Source: https://context7.com/yidun/nteslivedetect/llms.txt Add the NTESLiveDetect SDK to your project using CocoaPods. You can specify a version or integrate specific modules like 'Basic' or 'Nenn'. ```ruby # Podfile 配置 # 集成最新版 SDK pod 'NTESLiveDetect' # 集成指定版本 SDK pod 'NTESLiveDetect', '~> 3.2.11' # 如需分模块集成 pod 'NTESLiveDetect/Basic' # 核心活体检测模块 pod 'NTESLiveDetect/Nenn' # 神经网络模块 ``` -------------------------------- ### Stop Live Detection Process on Main Thread Source: https://context7.com/yidun/nteslivedetect/llms.txt Stop the current live detection flow by calling `stopLiveDetect` on the main thread. This should be done after receiving detection results or when needing to abort the process. It's crucial to ensure the manager is nilled out after stopping. ```Objective-C // 在检测完成后停止 - (void)onDetectionComplete:(NTESLDStatus)status { dispatch_async(dispatch_get_main_queue(), ^{ [self.detectManager stopLiveDetect]; self.detectManager = nil; }); } // 用户主动取消检测 - (IBAction)cancelButtonTapped:(id)sender { dispatch_async(dispatch_get_main_queue(), ^{ [self.detectManager stopLiveDetect]; [self dismissViewControllerAnimated:YES completion:nil]; }); } // 页面销毁时确保停止检测 - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; if (self.detectManager) { [self.detectManager stopLiveDetect]; } } ``` -------------------------------- ### Cancel Live Detection Source: https://context7.com/yidun/nteslivedetect/llms.txt Stops the live detection process, invokes the completion block with failure, and dismisses the current view controller. ```objective-c - (void)cancelDetection { [self.detectManager stopLiveDetect]; if (self.completionBlock) { self.completionBlock(NO, nil); } [self dismissViewControllerAnimated:YES completion:nil]; } ``` -------------------------------- ### Handle Status Changes via Notification Source: https://context7.com/yidun/nteslivedetect/llms.txt Processes status updates received through NSNotification. Updates the UI on the main thread based on action completion or exceptions. ```objective-c - (void)onStatusChange:(NSNotification *)notification { dispatch_async(dispatch_get_main_queue(), ^{ NSDictionary *action = notification.userInfo[@"action"]; NSString *exception = notification.userInfo[@"exception"]; if (action) { for (NSNumber *key in action.allKeys) { BOOL done = [action[key] boolValue]; self.statusLabel.text = done ? @"✓ 动作完成" : [self promptForAction:key.integerValue]; } } else if (exception) { self.statusLabel.text = [self messageForException:exception.integerValue]; } }); } ``` -------------------------------- ### Remove Notification Observer on Dealloc Source: https://context7.com/yidun/nteslivedetect/llms.txt Ensures that the notification center observer is removed when the object is deallocated to prevent memory leaks and unexpected behavior. ```objective-c - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.