Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift如何使用pin码访问钥匙链_Swift_Login_Touch - Fatal编程技术网

Swift如何使用pin码访问钥匙链

Swift如何使用pin码访问钥匙链,swift,login,touch,Swift,Login,Touch,这是我的touchId函数代码。我想让它诉诸于让用户输入pin码,他们用来解锁他们的手机,以验证他们的身份和登录,而无需键入用户名和密码。但我只希望他们在触摸ID不工作或不可用时使用此选项 我该怎么做呢 @IBAction func touchIDLogin(sender: AnyObject) { let authenticationContext = LAContext() var error: NSError? //check if device support

这是我的touchId函数代码。我想让它诉诸于让用户输入pin码,他们用来解锁他们的手机,以验证他们的身份和登录,而无需键入用户名和密码。但我只希望他们在触摸ID不工作或不可用时使用此选项

我该怎么做呢

 @IBAction func touchIDLogin(sender: AnyObject) {
    let authenticationContext = LAContext()
    var error: NSError?

    //check if device supports touch id, if not show error and stop
    guard authenticationContext.canEvaluatePolicy(.DeviceOwnerAuthenticationWithBiometrics, error: &error) else{
        displayAlert("TOUCH ID ERROR", msg: "This device does not support TouchID", option: false)
        return
    }

    authenticationContext.evaluatePolicy(.DeviceOwnerAuthenticationWithBiometrics, localizedReason: "Verify who you are to login", reply: {[unowned self](success, error) -> Void in
        if(success){

            //Fingerprint recognized
            var stored_pass = ""
            var stored_user = ""
            stored_pass = (self.my_keychain_wrapper.myObjectForKey("v_Data") as? String)!
            stored_user = (NSUserDefaults.standardUserDefaults().valueForKey("username") as? String)!
            if(!stored_pass.isEmpty || !stored_user.isEmpty){
                PFUser.logInWithUsernameInBackground(stored_user, password: stored_pass, block: { (user, error) -> Void in

                    //unsuccessful login display error message
                    if user == nil {
                        if let error_string = error!.userInfo["error"] as? String{
                            self.displayAlert("ERROR IN LOGIN", msg: error_string, option: false)
                        }
                    }

                    //successful login
                    else{
                        self.performSegueWithIdentifier("dashboard_segue", sender: self)
                    }
                })
            }
            else{
                self.displayAlert("LOGIN ERROR", msg: "No valid login credentials were found", option: false)
            }
        }

            //error check
        else{
            if let error = error{
                let message = self.errorMessageForLAErrorCode(error.code)
                self.displayAlert("TOUCH ID ERROR", msg: message, option: false)
            }
        }
        })
}

不幸的是,iOS没有提供根据系统密码验证条目的方法


如果touchID失败,应用程序可能需要管理自己的密码。允许应用程序使用与系统UI非常相似的UI管理密码,您可以鼓励用户将应用程序密码设置为系统的密码。

不幸的是,iOS没有提供根据系统密码验证条目的方法


如果touchID失败,应用程序可能需要管理自己的密码。允许应用程序使用与系统UI非常相似的UI管理密码,您还可以鼓励用户将应用程序密码设置为系统密码。

我认为您需要管理自己的pin码,并将其用作触摸ID故障的后备措施。这有点帮助,但我仍然不知道如何利用它:/I我认为您需要管理自己的pin码,并将其用作触摸ID故障的后备措施。这有点帮助,但我仍然不知道如何利用它:/