Skip to content

Resetting the license cache#

This topic applies to LUNA ID for iOS only.

We recommend that you reset license cache when you update your app. To do this:

1․ Create the LCLunaConfiguration.resetLicenseCache() function to check the application version and reset the license cache:

    import Foundation

    func checkAndResetLicenseCache() {
        let currentAppVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String
        let savedAppVersion = UserDefaults.standard.string(forKey: "AppVersion")

        if currentAppVersion != savedAppVersion {
            LCLunaConfiguration.resetLicenseCache()
            UserDefaults.standard.set(currentAppVersion, forKey: "AppVersion")
        }
    }

2․ Call this function when the application starts:

  • With UIKit in the AppDelegate.swift file:
    @main
    class AppDelegate: UIResponder, UIApplicationDelegate {

        var window: UIWindow?

        func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
            checkAndResetLicenseCache()

            ...
            return true
        }
    }
  • With SwiftUI in the App.swift file:
    @main
    struct YourApp: App {
        init() {
            checkAndResetLicenseCache()
        }

        var body: some Scene {
            WindowGroup {
                ContentView()
            }
        }
    }