// THE PHONE'S OWN LOCK, asked by any app that keeps something out of sight behind it: Sites' hidden sites, Cinemas'// Hidden. One helper, so every app asks it the same way and says the same thing when the phone has none.#if os(iOS)importLocalAuthenticationimport UIKitenumDeviceLock {/// Whether this phone has a screen lock (Face ID, Touch ID or a passcode) to ask.staticvar isSet: Bool {var error: NSError?return LAContext().canEvaluatePolicy(.deviceOwnerAuthentication, error: &error) }/// The phone's own lock, asked with `reason`: true once it passes. False when it fails, is cancelled, or the phone/// has no lock (ask `isSet` first to tell that apart).staticfunc ask(_ reason: String) async -> Bool {let context = LAContext()var error: NSError?guard context.canEvaluatePolicy(.deviceOwnerAuthentication, error: &error) else { returnfalse }return (try? await context.evaluatePolicy(.deviceOwnerAuthentication, localizedReason: reason)) == true }/// The phone's Settings, where a screen lock is set (iOS opens no deeper page than the app's own for anyone). @MainActor staticfunc openSettings() {guardlet url = URL(string: UIApplication.openSettingsURLString) else { return } UIApplication.shared.open(url) }}#endif