【问题标题】:Request iOS face id permission again when it was denied first time by user用户第一次拒绝时再次请求 iOS 人脸 ID 权限
【发布时间】:2020-07-20 21:06:37
【问题描述】:

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

我的问题是: 如果用户拒绝使用face id,有什么办法可以在不卸载应用程序的情况下再次请求它。

【问题讨论】:

    标签: ios swift face-id


    【解决方案1】:

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

    如果是notDetermined,您可以调出您已经在做的请求访问,如果被拒绝,您可以让用户选择转到设置 -> YourAppName 以授予 FaceID 访问您的应用程序。

    以下是来自以下答案的示例:Reference Question

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

    【讨论】:

    • 这不能应用于 FaceID。摄像头访问不是一回事,FaceID 没有状态表明它是否已获得授权
    猜你喜欢
    • 2018-01-05
    • 2018-09-29
    • 1970-01-01
    • 2018-01-20
    • 1970-01-01
    • 1970-01-01
    • 2019-12-01
    • 2020-09-02
    • 1970-01-01
    相关资源
    最近更新 更多