I want to implement local authentication security in my iOS app but I'm getting an error and not able to figure out why I'm getting this.
I'm using iPhone 5s. Is that matters?
Code:
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)
}
}
}
Error:
Thanks in advance.