Ver-ID-UI-Beta 2.0.0-beta.04

Ver-ID-UI-Beta 2.0.0-beta.04

David ThielkeJakub Dolejs 维护。



 
依存于
RxSwift~> 5
RxCocoa~> 5
Ver-ID-Core-Beta= 2.0.0-beta.04
 

Ver-ID-UI-Beta 2.0.0-beta.04

  • Jakub Dolejs

Cocoapods

适用于 iOS 的 Ver-ID UI

预备知识

最低 iOS 版本为 10.3。

要构建此项目并运行示例应用,您需要一台装有以下应用程序的 Apple Mac 电脑:

安装

  1. 打开 终端 并输入以下命令

    git clone https://github.com/AppliedRecognition/Ver-ID-UI-iOS.git
    cd Ver-ID-UI-iOS
    pod install
    open VerIDUI.xcworkspace
  2. VerIDUI.xcworkspace 应现在在 Xcode 中打开。

  3. 您现在可以在 iOS 设备上构建和运行 Ver-ID 样本 目标。

将 Ver-ID 添加到您的项目中

  1. 注册您的应用程序。您将需要您的应用程序的包标识符。

  2. 注册您的应用程序将为您的应用程序生成一个评估许可证。许可证有效期为 30 天。如果您需要生产许可证,请联系 Applied Recognition

  3. 完成注册后,您将收到一个名为 Ver-ID identity.p12 的文件和一个密码。将密码复制到安全位置,并将 Ver-ID identity.p12 文件添加到您的应用中。

    • 在 Xcode 中打开您的项目。
    • 从顶部菜单选择 文件/将文件添加到 “[您的项目名称]”... 或按 ⌥⌘A 并浏览选中下载的 Ver-ID identity.p12 文件。
    • 通过点击对话框左下角的 选项 按钮来显示选项。
    • 目标 下,勾选 如有需要复制项目
    • 添加到目标 下选择您的应用目标。
  4. Ver-ID 需要您在注册时收到的密码来构建一个 VerIDSDKIdentity 实例。

    • 您可以在创建 VerIDFactory 实例时指定密码

      let identity = try VerIDIdentity(password: "your password goes here")
    • 或者您可以在应用的 Info.plist 中添加密码

      <key>com.appliedrec.verid.password</key>
      <string>your password goes here</string>

      并在不使用密码参数的情况下构建身份

      let identity = try VerIDIdentity()        
  5. VerIDIdentity 实例传递给 VerIDFactory 构造函数

    let veridFactory = VerIDFactory(identity: identity)
  6. 如果您的项目使用 CocoaPods 进行依赖管理,请打开项目的 Podfile。如果没有安装 CocoaPods,请确保已安装并在项目文件夹中创建一个名为 Podfile 的文件(没有扩展名)。

  7. 假设您的项目名为 MyProject,并且它有一个名为 MyApp 的应用目标。在文本编辑器中打开 Podfile 并输入以下内容

    project 'MyProject.xcodeproj'
    workspace 'MyProject.xcworkspace'
    platform :ios, '10.3'
    target 'MyApp' do
        use_frameworks!
        pod 'Ver-ID-UI'
    
        # The following script sets the BUILD_LIBRARY_FOR_DISTRIBUTION build setting
        # to YES and removes the setting from the pod dependencies. Without it the
        # project will compile but it will fail to run. 
        post_install do |installer|
            installer.pods_project.build_configurations.each do |config|
                config.build_settings['BUILD_LIBRARY_FOR_DISTRIBUTION'] = 'YES'
            end
            installer.pods_project.targets.each do |target|
                target.build_configurations.each do |config|
                    config.build_settings.delete 'BUILD_LIBRARY_FOR_DISTRIBUTION'
                end
            end
        end
    end

    请确保包含 post_install 脚本。没有它,您的应用会崩溃。

  8. 保存 Podfile。打开 终端 并导航到您的项目文件夹。然后输入

    pod install
  9. 您现在可以在 MyProject.xcworkspace 中打开 Xcode,并且 Ver-ID 将可在您的应用 MyApp 中使用。

运行 Ver-ID 会话

  1. 在运行 Ver-ID UI 会话之前,您需要导入 VerIDCore 框架并创建一个 VerID 实例。
  2. 让您的类实现 VerIDFactoryDelegate 协议。您将收到关于 VerID 实例创建或创建失败的回调。
  3. 在运行 Ver-ID 会话的类中导入 VerIDUI
  4. VerID 实例和会话设置传递给 VerIDSession 构造函数。

示例

import UIKit
import VerIDCore
import VerIDUI

class MyViewController: UIViewController, VerIDFactoryDelegate, VerIDSessionDelegate {
    
    func runLivenessDetection() {
        guard let identity = try? VerIDSDKIdentity() else {
            // Failed to create SDK identity
            return
        }
        // You may want to display an activity indicator as the instance creation may take up to a few seconds
        let factory = VerIDFactory(identity: identity)
        // Set your class as the factory's delegate
        // The delegate methods will be called when the session is created or if the creation fails
        factory.delegate = self
        // Create an instance of Ver-ID
        factory.createVerID()
    }
    
    // MARK: - Ver-ID factory delegate
    
    func veridFactory(_ factory: VerIDFactory, didCreateVerID instance: VerID) {
        // Ver-ID instance was created
        // Create liveness detection settings
        let settings = LivenessDetectionSessionSettings()
        // Create a Ver-ID UI session
        let session = VerIDSession(environment: instance, settings: settings)
        // Set your class as a delegate of the session to receive the session outcome
        session.delegate = self
        // Start the session
        session.start()
    }
    
    func veridFactory(_ factory: VerIDFactory, didFailWithError error: Error) {
        NSLog("Failed to create Ver-ID instance: %@", error.localizedDescription)
    }
    
    // MARK: - Session delegate
    
    func didFinishSession(_ session: VerIDSession, withResult result: VerIDSessionResult) {
        // Session finished successfully
    }
    
    // MARK: Optional session delegate methods
    
    func didCancelSession(_ session: VerIDSession) {
        // Session was canceled
    }
    
    func shouldDisplayResult(_ result: VerIDSessionResult, ofSession session: VerIDSession) -> Bool {
        // Return `true` to display the result of the session
        return true
    }
    
    func shouldSpeakPromptsInSession(_ session: VerIDSession) -> Bool {
        // Return `true` to speak prompts in the session
        return true
    }
    
    func shouldRecordVideoOfSession(_ session: VerIDSession) -> Bool {
        // Return `true` to record a video of the session
        return true
    }
    
    func cameraPositionForSession(_ session: VerIDSession) -> AVCaptureDevice.Position {
        // Return `AVCaptureDevice.Position.back` to use the back camera instead of the front (selfie) camera
        return .back
    }
}

API参考文档