简体   繁体   English

当用户第一次被拒绝时,再次请求 iOS 人脸 ID 权限

[英]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.在为应用程序请求人脸 ID 权限后,我们会收到允许用户授予或拒绝使用此技术的 Apple 警报。

在此处输入图像描述

My question is: If the user deny the use of face id, is there any solution to request it again without uninstalling the application.我的问题是:如果用户拒绝使用face id,是否有任何解决方案可以在不卸载应用程序的情况下再次请求它。

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 .您可以做的是,当您请求 Face ID 时,您应该检查授权状态,可以是notDeterminedauthorizeddeniedrestricted

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.在未确定的情况下,您notDetermined您已经在执行的请求访问,如果被拒绝,您可以为用户提供 go 到 Settings -> YourAppName 的选项,以授予 FaceID 访问您的应用程序的权限。

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.它适用于相机访问,但您应该能够非常简单地将其应用于 FaceID。

@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:然后在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)
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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