简体   繁体   中英

Request iOS face id permission again when it was denied first time by user

After requesting face id permission for an application, we get the apple alert that allow the user to grant or deny the use of this technologie.

在此处输入图像描述

My question is: If the user deny the use of face id, is there any solution to request it again without uninstalling the application.

You can request it again, but not in the same way as the first time. What you can do is when you request for Face ID, you should check on the authorization status, which can either be notDetermined , authorized , denied or restricted .

In the case that it is notDetermined you can bring up the request access that you are already doing, and if it is denied you can give the user the option to go to Settings -> YourAppName to give FaceID access to your app.

Here is an example taken from the following answer: Reference Question

It is for Camera Access but you should be able to apply it to FaceID pretty simply.

@IBAction func goToCamera()
{
    let status = AVCaptureDevice.authorizationStatus(for: AVMediaType.video)
    switch (status) {
    case .authorized:
        self.popCamera()
    case .notDetermined:
        AVCaptureDevice.requestAccess(for: AVMediaType.video) { (granted) in
            if (granted) {
                self.popCamera()
            } else {
                self.camDenied()
            }
        }
    case .denied:
        self.camDenied()
    case .restricted:
        let alert = UIAlertController(title: "Restricted",
                                      message: "You've been restricted from using the camera on this device. Without camera access this feature won't work. Please contact the device owner so they can give you access.",
                                      preferredStyle: .alert)

        let okAction = UIAlertAction(title: "OK", style: .default, handler: nil)
        alert.addAction(okAction)
        self.present(alert, animated: true, completion: nil)
    }
}

Then in the camDenied function:

func camDenied() {
    DispatchQueue.main.async {
            var alertText = "It looks like your privacy settings are preventing us from accessing your camera to do barcode scanning. You can fix this by doing the following:\n\n1. Close this app.\n\n2. Open the Settings app.\n\n3. Scroll to the bottom and select this app in the list.\n\n4. Turn the Camera on.\n\n5. Open this app and try again."

            var alertButton = "OK"
            var goAction = UIAlertAction(title: alertButton, style: .default, handler: nil)

            if UIApplication.shared.canOpenURL(URL(string: UIApplicationOpenSettingsURLString)!) {
                alertText = "It looks like your privacy settings are preventing us from accessing your camera to do barcode scanning. You can fix this by doing the following:\n\n1. Touch the Go button below to open the Settings app.\n\n2. Turn the Camera on.\n\n3. Open this app and try again."

                alertButton = "Go"

                goAction = UIAlertAction(title: alertButton, style: .default, handler: {(alert: UIAlertAction!) -> Void in
                    UIApplication.shared.open(URL(string: UIApplicationOpenSettingsURLString)!, options: [:], completionHandler: nil)
                })
            }

            let alert = UIAlertController(title: "Error", message: alertText, preferredStyle: .alert)
            alert.addAction(goAction)
            self.present(alert, animated: true, completion: nil)
    }
}

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