DOT iOS Face 7.0.0

This guide describes how to migrate DOT iOS Face version 6.x to version 7.0.0. Only the most important changes are highlighted in this guide. For more details, see the iOS sample.

Migration Steps

Basic Setup

  • Replace DotFaceLibrary.shared.initialize() with DotSdk.shared.initialize(). This operation should be called on background thread. DOT iOS SDK Samples shows how to do it.
  • Replace DotFaceLibrary.shared.deinitialize() with DotSdk.shared.deinitialize().
  • Replace DotFaceLibrary.shared.isInitialized with DotSdk.shared.isInitialized.

Before

extension AppDelegate: DotFaceLibraryDelegate {

    private func initializeDotFaceLibrary() {

        print("DotFace license ID: " + DotFaceLibrary.shared.licenseId)

        if let url = Bundle.main.url(forResource: "dot_face_license", withExtension: "lic") {
            do {
                let license = try Data(contentsOf: url)
                let configuration = DotFaceLibraryConfiguration(license: license,
                                                                modules: [DotFaceDetectionFastModule.shared,
                                                                          DotFacePassiveLivenessModule.shared,
                                                                          DotFaceVerificationModule.shared,
                                                                          DotFaceEyeGazeLivenessModule.shared,
                                                                          DotFaceBackgroundUniformityModule.shared,
                                                                          DotFaceExpressionNeutralModule.shared])
                DotFaceLibrary.shared.setDelegate(self)
                DotFaceLibrary.shared.initialize(configuration: configuration)
            } catch {
                print(error.localizedDescription)
            }
        }
    }
    
    private func deinitializeDotFaceLibrary() {
        DotFaceLibrary.shared.deinitialize()
    }
    
    private func isDotFaceLibraryInitialized() -> Bool {
        return DotFaceLibrary.shared.isInitialized
    }

    func dotFaceLibraryInitializationFinished(_ dotFaceLibrary: DotFaceLibrary, result: DotFaceLibrary.Result) {
        print(#function, "isSuccess:", result.code == .ok)
    }

    func dotFaceLibraryDeinitializationFinished(_ dotFaceLibrary: DotFaceLibrary, result: DotFaceLibrary.Result) {
        print(#function, "isSuccess:", result.code == .ok)
    }
}

After

private func initializeDotSdk() {

    print("Bundle ID: " + DotSdk.shared.bundleId)

    if let url = Bundle.main.url(forResource: "dot_license", withExtension: "lic") {
        do {
            let license = try Data(contentsOf: url)
            let dotFaceLibraryConfiguration = createDotFaceLibraryConfiguration()
            let dotSdkConfiguration = createDotSdkConfiguration(license: license, dotFaceLibraryConfiguration: dotFaceLibraryConfiguration)
            try DotSdk.shared.initialize(configuration: dotSdkConfiguration)
        } catch {
            presentErrorAlert("Failed to initialize DotSdk: \(error.localizedDescription)")
        }
    } else {
        presentErrorAlert("Failed to initialize DotSdk: License not found.")
    }
}

private func createDotFaceLibraryConfiguration() -> DotFaceLibraryConfiguration {
    return .init(
        modules: [
            DotFaceDetectionFastModule.shared,
            DotFacePassiveLivenessModule.shared,
            DotFaceVerificationModule.shared,
            DotFaceBackgroundUniformityModule.shared,
            DotFaceExpressionNeutralModule.shared
        ]
    )
}

private func createDotSdkConfiguration(license: Data, dotFaceLibraryConfiguration: DotFaceLibraryConfiguration) -> DotSdkConfiguration {
    return DotSdkConfiguration(
        licenseBytes: license,
        libraries: [
            DotFaceLibrary(configuration: dotFaceLibraryConfiguration),
            DotDocumentLibrary(),
            DotNfcLibrary()
        ]
    )
}

private func deinitializeDotSdk() {
    DotSdk.shared.deinitialize()
}

private func isDotSdkInitialized() -> Bool {
    return DotSdk.shared.isInitialized
}