iOS开发中Swift 指纹验证功能模块实例代码

时间:2021-11-16 04:17:54

iOS调用TouchID代码:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
override func viewDidLoad() {
   super.viewDidLoad()
   let context = LAContext()
   var error: NSError? = nil
   let canEvaluatePolicy = context.canEvaluatePolicy(LAPolicy.deviceOwnerAuthenticationWithBiometrics, error: &error) as Bool
   if error != nil {
     print(error!.localizedDescription as String)
   }
   if canEvaluatePolicy {
     print("有指纹验证功能")
     context.evaluatePolicy(LAPolicy.deviceOwnerAuthenticationWithBiometrics, localizedReason: "放上您的狗爪", reply: { (success: Bool, error: Error?) in
       if success {
         print("验证成功")
       } else {
         print("验证失败: \(error?.localizedDescription)")
       }
     })
   } else {
     print("还没开启指纹验证呢")
   }
 }

以上所述是小编给大家介绍的iOS开发中Swift 指纹验证功能模块实例代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对服务器之家网站的支持!

原文链接:http://www.jianshu.com/p/60dc98e4d051