From 1947b326a4d41bd2fb7716c877fdc8c5affa0e74 Mon Sep 17 00:00:00 2001 From: Max Goedjen Date: Sat, 20 Jan 2024 19:47:55 -0800 Subject: [PATCH] Scheudle timer on mian --- .../SecureEnclaveStore.swift | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/Sources/Packages/Sources/SecureEnclaveSecretKit/SecureEnclaveStore.swift b/Sources/Packages/Sources/SecureEnclaveSecretKit/SecureEnclaveStore.swift index 194eab7..31bf746 100644 --- a/Sources/Packages/Sources/SecureEnclaveSecretKit/SecureEnclaveStore.swift +++ b/Sources/Packages/Sources/SecureEnclaveSecretKit/SecureEnclaveStore.swift @@ -198,16 +198,18 @@ extension SecureEnclave { self?.persistedAuthenticationContexts[secret] = context // Contexts will expire within LATouchIDAuthenticationMaximumAllowableReuseDuration unless we periodically refresh them if duration > LATouchIDAuthenticationMaximumAllowableReuseDuration { - Timer.scheduledTimer(withTimeInterval: LATouchIDAuthenticationMaximumAllowableReuseDuration - 10, repeats: true) { [weak self] timer in - print("Refreshing context") - guard let refreshContext = self?.persistedAuthenticationContexts[secret] else { return } - guard refreshContext.valid else { - timer.invalidate() - return - } - refreshContext.context.evaluatePolicy(.deviceOwnerAuthentication, localizedReason: "Refresh") { success, _ in - guard success else { return } - print("Refreshed") + DispatchQueue.main.async { + Timer.scheduledTimer(withTimeInterval: LATouchIDAuthenticationMaximumAllowableReuseDuration - 10, repeats: true) { [weak self] timer in + print("Refreshing context") + guard let refreshContext = self?.persistedAuthenticationContexts[secret] else { return } + guard refreshContext.valid else { + timer.invalidate() + return + } + refreshContext.context.evaluatePolicy(.deviceOwnerAuthentication, localizedReason: "Refresh") { success, _ in + guard success else { return } + print("Refreshed") + } } } }