Ver-ID UI for iOS
先决条件
最低 iOS 版本为 10.3。
为了构建此项目并运行示例应用,您需要一台具有以下应用的 Apple Mac 计算机:
安装
-
打开 终端 并输入以下命令:
git clone https://github.com/AppliedRecognition/Ver-ID-UI-iOS.git cd Ver-ID-UI-iOS pod install open VerIDUI.xcworkspace
-
VerIDUI.xcworkspace 现应在 Xcode 中打开。
-
现在您可以在您的 iOS 设备上构建并运行 Ver-ID 示例 目标。
将 Ver-ID 添加到您自己的项目中
-
注册您的应用。您将需要您的应用捆绑标识符。
-
注册您的应用将为您生成一个评估许可证。该许可证有效期为 30 天。如果您需要生产许可证,请联系 Applied Recognition。
-
完成注册后,您将收到一个名为 Ver-ID identity.p12 的文件和一个密码。将密码复制到安全位置,并在您的应用中添加 Ver-ID identity.p12 文件。
- 在 Xcode 中打开您的项目。
- 从顶部菜单中选择 文件/将文件添加到 “[您的项目名称]”... 或按 ⌥⌘A 并浏览以选择下载的 Ver-ID identity.p12 文件。
- 通过点击对话框左下角的 选项 按钮展开选项。
- 在 目标 下勾选 如有需要,则复制项。
- 在 添加到目标 下选择您的应用目标。
-
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()
-
-
将
VerIDIdentity
的实例传递给VerIDFactory
构造函数let veridFactory = VerIDFactory(identity: identity)
-
如果您的项目使用 CocoaPods 进行依赖关系管理,请打开项目的 Podfile。否则请确保已安装 CocoaPods 并将其位于项目文件夹中创建一个名为 Podfile 的文件(没有扩展名)。
-
假设您的项目名为 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
脚本。没有它,您的应用将崩溃。 -
保存 Podfile。打开 终端 并导航到您的项目文件夹。然后输入
pod install
-
现在您可以在 Xcode 中打开 MyProject.xcworkspace,并可以使用 Ver-ID 在您的应用 MyApp 中使用。
运行 Ver-ID 会话
- 在运行 Ver-ID UI 会话之前,您需要导入
VerIDCore
框架并创建一个VerID
实例。 - 让您的类实现
VerIDFactoryDelegate
协议。当创建VerID
实例或创建失败时,您将收到回调。 - 在运行 Ver-ID 会话的类中导入
VerIDUI
。 - 将
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
}
}