我想在我的iOS应用程序中实现本地身份验证安全性,但我是
得到一个错误,不能弄清楚为什么我得到这个.
得到一个错误,不能弄清楚为什么我得到这个.
我正在使用iPhone 5s.这很重要吗
码:
- import UIKit
- import LocalAuthentication
- class ViewController: UIViewController {
- override func viewDidLoad() {
- super.viewDidLoad()
- // Do any additional setup after loading the view,typically from a nib.
- }
- override func didReceiveMemoryWarning() {
- super.didReceiveMemoryWarning()
- // Dispose of any resources that can be recreated.
- }
- @IBAction func action(_ sender: Any) {
- authenticateUser()
- }
- func authenticateUser() {
- let authContext : LAContext = LAContext()
- var error: NSError?
- if authContext.canEvaluatePolicy(LAPolicy.deviceOwnerAuthenticationWithBiometrics,error: &error){
- authContext.evaluatePolicy(LAPolicy.deviceOwnerAuthenticationWithBiometrics,localizedReason: "Biometric Check for application",reply: {(successful: Bool,error: NSError?) -> Void in
- if successful{
- print("TouchID Yes")
- }
- else{
- print("TouchID No")
- }
- } as! (Bool,Error?) -> Void)
- }
- else{
- authContext.evaluatePolicy(LAPolicy.deviceOwnerAuthentication,localizedReason: "Enter your Passcode",reply: {
- (successful: Bool,error: NSError?) in
- if successful{
- print("PassCode Yes")
- }
- else{
- print("PassCode No")
- }
- } as! (Bool,Error?) -> Void)
- }
- }
- }
错误:
提前致谢.
解决方法
没有类型转换的代码应该可以工作
- func authenticateUser() {
- let authContext : LAContext = LAContext()
- var error: NSError?
- if authContext.canEvaluatePolicy(LAPolicy.deviceOwnerAuthenticationWithBiometrics,error: &error){
- authContext.evaluatePolicy(LAPolicy.deviceOwnerAuthenticationWithBiometrics,reply: {successful,error -> Void in
- if successful{
- print("TouchID Yes")
- }
- else{
- print("TouchID No")
- }
- }
- )
- }
- else{
- authContext.evaluatePolicy(LAPolicy.deviceOwnerAuthentication,reply: {
- successful,error in
- if successful{
- print("PassCode Yes")
- }
- else{
- print("PassCode No")
- }
- }
- )
- }
- }