Jelajahi Sumber

Add fallback to passcode for Trio Bolus and Meal

codebymini 10 bulan lalu
induk
melakukan
613ccb39d6
2 mengubah file dengan 36 tambahan dan 6 penghapusan
  1. 18 3
      LoopFollow/Remote/TRC/BolusView.swift
  2. 18 3
      LoopFollow/Remote/TRC/MealView.swift

+ 18 - 3
LoopFollow/Remote/TRC/BolusView.swift

@@ -130,16 +130,31 @@ struct BolusView: View {
     private func authenticateUser(completion: @escaping (Bool) -> Void) {
         let context = LAContext()
         var error: NSError?
-
         let reason = "Confirm your identity to send bolus."
 
         if context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &error) {
             context.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: reason) { success, _ in
                 DispatchQueue.main.async {
-                    completion(success)
+                    if success {
+                        completion(true)
+                    } else {
+                        // Biometric failed, try passcode
+                        self.tryPasscode(completion: completion)
+                    }
                 }
             }
-        } else if context.canEvaluatePolicy(.deviceOwnerAuthentication, error: &error) {
+        } else {
+            // No biometrics available, try passcode directly
+            tryPasscode(completion: completion)
+        }
+    }
+    
+    private func tryPasscode(completion: @escaping (Bool) -> Void) {
+        let context = LAContext()
+        var error: NSError?
+        let reason = "Confirm your identity to send bolus."
+
+        if context.canEvaluatePolicy(.deviceOwnerAuthentication, error: &error) {
             context.evaluatePolicy(.deviceOwnerAuthentication, localizedReason: reason) { success, _ in
                 DispatchQueue.main.async {
                     completion(success)

+ 18 - 3
LoopFollow/Remote/TRC/MealView.swift

@@ -304,16 +304,31 @@ struct MealView: View {
     private func authenticateUser(completion: @escaping (Bool) -> Void) {
         let context = LAContext()
         var error: NSError?
-
         let reason = "Confirm your identity to send bolus."
 
         if context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &error) {
             context.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: reason) { success, _ in
                 DispatchQueue.main.async {
-                    completion(success)
+                    if success {
+                        completion(true)
+                    } else {
+                        // Biometric failed, try passcode
+                        self.tryPasscode(completion: completion)
+                    }
                 }
             }
-        } else if context.canEvaluatePolicy(.deviceOwnerAuthentication, error: &error) {
+        } else {
+            // No biometrics available, try passcode directly
+            tryPasscode(completion: completion)
+        }
+    }
+    
+    private func tryPasscode(completion: @escaping (Bool) -> Void) {
+        let context = LAContext()
+        var error: NSError?
+        let reason = "Confirm your identity to send bolus."
+
+        if context.canEvaluatePolicy(.deviceOwnerAuthentication, error: &error) {
             context.evaluatePolicy(.deviceOwnerAuthentication, localizedReason: reason) { success, _ in
                 DispatchQueue.main.async {
                     completion(success)