Verifying license validity#
Applies to LUNA ID for iOS only.
This article describes the recommended methods for verifying licenses for both common face recognition and OCR features in LUNA ID for iOS.
Note: Automatic and customized validation methods are deprecated and will be removed in future releases.
Common license validation#
The LCLunaIDServiceBuilder class provides a unified method to activate and validate a license for face recognition features:
if let error = LunaCore.LCLunaIDServiceBuilder.activateLicense(withConfig: lunaConfig, license: license) {
debugPrint("license activation FAILED with error: <\(error.localizedDescription)>")
return
}
OCR license validation#
The OCR functionality requires a separate license. To validate the OCR license:
- Ensure your license file contains the
OCRfield. - Use the following code snippet to validate the license:
let service = LROCRServiceBuilder.createOCRService()
let licenseConfig = LunaCore.LCLicenseConfig.userDefaults()
service.checkLicense(licenseConfig: licenseConfig) { result in
switch result {
case .failure(let error):
case .success:
}
}
Automatic validation#
Important: This approach is deprecated and will be unavailable in future releases.
This approach checks the license in silent mode, meaning the license validation occurs automatically during the LCLunaIDServiceBuilder.buildLunaIDService() call. Here's how it works:
// Creating LunaID configuration
let configFilePath = Bundle.main.path(forResource: "luna_config", ofType: "plist") ?? ""
let lunaConfig: LunaCore.LCLunaConfiguration = LunaCore.LCLunaConfiguration(plistFilePath: configFilePath)
// Creating LunaID service
let lunaIDService: LunaCore.LCLunaIDServiceProtocol = LCLunaIDServiceBuilder.buildLunaIDService(withConfig: lunaConfig)
In this method, the LunaCore.LCLunaConfiguration.plistLicenseFileName property specifies the name of the .plist file where LUNA ID will look for license information. The system will attempt to locate the file named "{LunaCore.LCLunaConfiguration.plistLicenseFileName}.plist" in the main bundle.
Customized method#
Important: This approach is deprecated and will be unavailable in future releases.
If you want to explicitly validate the license and ensure that the license data is correct, you can use the following customized approach:
// Creating LunaID configuration
let configFilePath = Bundle.main.path(forResource: "luna_config", ofType: "plist") ?? ""
let lunaConfig = LunaCore.LCLunaConfiguration(plistFilePath: configFilePath)
// Creating LunaID service
let lunaIDService: LunaCore.LCLunaIDServiceProtocol = LCLunaIDServiceBuilder.buildLunaIDService(withConfig: lunaConfig)
// Creating license configuration
let licenseFilePath = Bundle.main.path(forResource: "vllicense", ofType: "plist") ?? ""
let licenseConfig = LunaCore.LCLicenseConfig(plistFilePath: licenseFilePath)
// Checking license configuration
if let error = lunaIDService.activateLicense(with: licenseConfig) {
debugPrint("Error while checking license on application startup: \(error)")
}
In this approach, although the silent license check is still performed when creating the LUNA ID service, you gain additional control. You can create a LunaCore.LCLicenseConfig object from any .plist file with a custom name and place it in any bundle. Afterward, you can explicitly invoke LunaCore.LCLunaIDServiceProtocol.activateLicense(). This method returns nil if the license is valid, or an Error object if the license is invalid.