第一次被用户拒绝后再次申请iOS人脸ID权限

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

在为应用程序请求面容 ID 权限后,我们收到允许用户授予或拒绝使用此技术的苹果警报。

我的问题是: 如果用户拒绝使用face id,有没有什么解决方案可以在不卸载应用的情况下重新请求。

您可以再次申请,但方式与第一次不同。你可以做的是,当你请求 Face ID 时,你应该检查授权状态,可以是 notDeterminedauthorizeddeniedrestricted

notDetermined 的情况下,你可以提出你已经在做的请求访问,如果被拒绝,你可以让用户选择去设置 -> YourAppName 给FaceID 访问您的应用程序。

这是从以下答案中摘录的示例:Reference Question

它用于 Camera Access,但您应该能够非常简单地将它应用于 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)
    }
}

然后在camDenied函数中:

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)
    }
}