Skip to content

Verifying license validity#

Applies to LUNA ID for iOS only.

To verify the license validity in LUNA ID, you can use either the default method or a customized approach depending on your requirements.

Default method#

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#

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.