简体   繁体   中英

On iOS 13 the biometric authentication alert does not show on older phones

On older iPhones such as the 6, 6s etc. The biometric authentication dialogue/alert is hidden. If you press the home button on the iPhone to authenticate via a fingerprint it still works, but the dialogue/alert is hidden, which is a source of confusion for users.

Various sources ( 1 ) ( 2 ) have reported this as an iOS 13 bug.

This worked correctly on iOS 12, the issue started on iOS 13.

My biometric auth code looks like this and is fired in a view controller's viewDidAppear method:

    let localAuthContext = LAContext()
    var error: NSError?
    if localAuthContext.canEvaluatePolicy(LAPolicy.deviceOwnerAuthenticationWithBiometrics, error: &error) {
        localAuthContext.evaluatePolicy(LAPolicy.deviceOwnerAuthenticationWithBiometrics, localizedReason: "SIGNIN.TITLE.Login".localized) { [weak self] (success, error) in
            if success {
                // success
            } else {
                // failure
            }
        }
    } else {
        // can't evaluate policy
    }

So, do I need to change something in my code for iOS 13, or is this an Apple issue?

It seems to be issue in processing. I've fixed this issue by showing it from main queue so it will surely show maybe after delay but it will not remain hidden.

DispatchQueue.main.async {

  if localAuthContext.canEvaluatePolicy(LAPolicy.deviceOwnerAuthenticationWithBiometrics, error: &error) {
    localAuthContext.evaluatePolicy(LAPolicy.deviceOwnerAuthenticationWithBiometrics, localizedReason: "SIGNIN.TITLE.Login".localized) { [weak self] (success, error) in
        if success {
            // success
        } else {
            // failure
        }
    }
  } else {
     // can't evaluate policy
  }

}

It just happens from iOS 13 and above. The solution is trying to call evaluate function twice like this:

let systemVersion = UIDevice.current.systemVersion
// Trick here: Try to do an pre-evaluate
if systemVersion.compare("13.0", options: .numeric) != .orderedAscending {
    context.evaluatePolicy(.deviceOwnerAuthentication, localizedReason: "Authenticate to open the app", reply: { (_, _) in
         //Ignore callback here
     })
}

context.evaluatePolicy(.deviceOwnerAuthentication, localizedReason: "Authenticate to open the app", reply: { (success, error) in
    // Handle callback here
})

Tested and work well for all iOS 13.xx versions so far.

This seems to be an Apple issue on older iOS 13 versions. I am unable to reproduce this issue from iOS 13.1.2 onwards.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM