1

I want to know how I can call the iOS to show the alert pop up from apple to give the app access to Face ID/ Touch ID , when the user disable them from settings of the app. I know that this is put in info plist, but when I disable them from settings, it is not showing the ask again:

Here is the image from diable: Here is the image from disable

Oliver
  • 8,169
  • 3
  • 15
  • 37
Resr
  • 15
  • 2
  • 5
    You only get to ask once. After that you need to direct the user back to settings to enable it. – Paulw11 Oct 17 '19 at 09:50

3 Answers3

1

If Face ID is turned off in the settings, it must be redirected to the settings to turn it back on.

0

As @Paulw11 mentioned, you only get to ask once. If the user denies access, the best you can do is ask them with an alert if they want to go to Settings to allow biometrics. Code would be something like this:

let alertController = UIAlertController (title: "Title", message: "Go to Settings?", preferredStyle: .alert)
let settingsAction = UIAlertAction(title: "Settings", style: .default) { (_) -> Void in

    guard let settingsUrl = URL(string: UIApplication.openSettingsURLString) else {
        return
    }

    if UIApplication.shared.canOpenURL(settingsUrl) {
        UIApplication.shared.open(settingsUrl, completionHandler: { (success) in
            print("Settings opened: \(success)") // Prints true
        })
    }
}
alertController.addAction(settingsAction)
let cancelAction = UIAlertAction(title: "Cancel", style: .default, handler: nil)
alertController.addAction(cancelAction)

present(alertController, animated: true, completion: nil)

As seen on this answer.

Have in mind that this will take the user from the app, but so far there is no other way of doing it.

Marina Aguilar
  • 1,151
  • 9
  • 26
-1

You need to check wether device can authenticate by biometrics or not.

Let's do this right before you call your function to authenticate.

func canAuthenByBioMetrics() -> Bool {
    let context = LAContext()
    var authError: NSError?

    if context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &authError) {
        return true
    } else {
        return false
    }
}

Show your code will be like:

if self.canAuthenByBioMetrics() {
    // Do you authentication
} else {
    // Ask user for enable permission or setup biometric if needed
}
jacob
  • 1,024
  • 9
  • 14