Parcourir la source

VLCKeychainCoordinator: fix that users weren't prompted for Touch or FaceID

(cherry picked from commit d3f80cbd527d2d99c7740e19cb38b311354e402e)
Carola Nitz il y a 7 ans
Parent
commit
11e3c8ec40
1 fichiers modifiés avec 8 ajouts et 3 suppressions
  1. 8 3
      Sources/KeychainCoordinator.swift

+ 8 - 3
Sources/KeychainCoordinator.swift

@@ -20,16 +20,20 @@ class KeychainCoordinator:NSObject, PAPasscodeViewControllerDelegate {
         return UserDefaults.standard.bool(forKey:kVLCSettingPasscodeOnKey)
     }
     private var laContext = LAContext()
+
+    //Since FaceID and TouchID are both set to 1 when the defaults are registered
+    //we have to double check for the biometry type to not return true even though the setting is not visible
+    //and that type is not supported by the device
     private var touchIDEnabled:Bool {
         var touchIDEnabled = UserDefaults.standard.bool(forKey:kVLCSettingPasscodeAllowTouchID)
-        if #available(iOS 11.0, *) {
+        if #available(iOS 11.0, *), laContext.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: nil) {
             touchIDEnabled = touchIDEnabled && laContext.biometryType == .touchID
         }
         return touchIDEnabled
     }
     private var faceIDEnabled:Bool {
         var faceIDEnabled = UserDefaults.standard.bool(forKey:kVLCSettingPasscodeAllowFaceID)
-        if #available(iOS 11.0, *) {
+        if #available(iOS 11.0, *), laContext.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: nil) {
             faceIDEnabled = faceIDEnabled && laContext.biometryType == .faceID
         }
         return faceIDEnabled
@@ -95,7 +99,8 @@ class KeychainCoordinator:NSObject, PAPasscodeViewControllerDelegate {
     }
 
     @objc private func appInForeground(notification:Notification) {
-        if let navigationController = UIApplication.shared.delegate?.window??.rootViewController?.presentedViewController as? UINavigationController, navigationController.topViewController is PAPasscodeViewController, touchIDEnabled {
+        if let navigationController = UIApplication.shared.delegate?.window??.rootViewController?.presentedViewController as? UINavigationController, navigationController.topViewController is PAPasscodeViewController,
+            touchIDEnabled || faceIDEnabled {
             touchOrFaceIDQuery()
         }
     }