Просмотр исходного кода

Add passcode fallback for Loop APNS insulin

codebymini 10 месяцев назад
Родитель
Сommit
b6d461aad6
1 измененных файлов с 19 добавлено и 4 удалено
  1. 19 4
      LoopFollow/Remote/LoopAPNS/LoopAPNSBolusView.swift

+ 19 - 4
LoopFollow/Remote/LoopAPNS/LoopAPNSBolusView.swift

@@ -326,13 +326,28 @@ struct LoopAPNSBolusView: View {
                     if success {
                         sendInsulinConfirmed()
                     } else {
-                        alertMessage = "Authentication failed"
-                        alertType = .error
-                        showAlert = true
+                        // Biometric authentication failed, try passcode fallback
+                        self.authenticateWithPasscode()
                     }
                 }
             }
         } else if context.canEvaluatePolicy(.deviceOwnerAuthentication, error: &error) {
+            // No biometrics available, go directly to passcode
+            authenticateWithPasscode()
+        } else {
+            alertMessage = "Authentication not available"
+            alertType = .error
+            showAlert = true
+        }
+    }
+
+    private func authenticateWithPasscode() {
+        let context = LAContext()
+        var error: NSError?
+
+        let reason = "Confirm your identity to send insulin."
+
+        if context.canEvaluatePolicy(.deviceOwnerAuthentication, error: &error) {
             context.evaluatePolicy(.deviceOwnerAuthentication, localizedReason: reason) { success, _ in
                 DispatchQueue.main.async {
                     if success {
@@ -345,7 +360,7 @@ struct LoopAPNSBolusView: View {
                 }
             }
         } else {
-            alertMessage = "Biometric authentication not available"
+            alertMessage = "Authentication not available"
             alertType = .error
             showAlert = true
         }