簡體   English   中英

當用戶第一次被拒絕時,再次請求 iOS 人臉 ID 權限

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

在為應用程序請求人臉 ID 權限后,我們會收到允許用戶授予或拒絕使用此技術的 Apple 警報。

在此處輸入圖像描述

我的問題是:如果用戶拒絕使用face id,是否有任何解決方案可以在不卸載應用程序的情況下再次請求它。

您可以再次請求,但方式與第一次不同。 您可以做的是,當您請求 Face ID 時,您應該檢查授權狀態,可以是notDeterminedauthorizeddeniedrestricted

在未確定的情況下,您notDetermined您已經在執行的請求訪問,如果被拒絕,您可以為用戶提供 go 到 Settings -> YourAppName 的選項,以授予 FaceID 訪問您的應用程序的權限。

這是取自以下答案的示例: 參考問題

它適用於相機訪問,但您應該能夠非常簡單地將其應用於 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 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