程序问答   发布时间:2022-06-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了如何重构 Face/Touch ID 实现? UIKit iOS 13.2+大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决如何重构 Face/Touch ID 实现? UIKit iOS 13.2+?

开发过程中遇到如何重构 Face/Touch ID 实现? UIKit iOS 13.2+的问题如何解决?下面主要结合日常开发的经验,给出你关于如何重构 Face/Touch ID 实现? UIKit iOS 13.2+的解决方法建议,希望对你解决如何重构 Face/Touch ID 实现? UIKit iOS 13.2+有所启发或帮助;

当付费用户可以启用此“额外”安全级别时,我已对应用实施了触控/面部 ID 身份验证。这是一个简单的 pdf 编辑器应用程序,因此在您成为付费用户并想使用它之前,它没有安全功能。

可以通过 UISwitch 在“设置”中启用生物识别身份验证。

如何重构 Face/Touch ID 实现? UIKit iOS 13.2+

这样,我怎么实现就够了?有什么改进的想法吗?

  1. 用户启用后,UISwitchisON 布尔值保存到 UserDefaults
  2. 我已经设置了 AuthenticationManager

`

class AuthenticationManager {
  static let shared = AuthenticationManager()
  var needsAuthentication = UserDefaults.standard.value(forKey: "toggledOn") as? Bool ?? false
  var context = LAContext()

  init(){}
    
  func unlockThe(UIVIEwController: UIVIEwController) {
    var error: NSError?
    
    // GetTing new context every time I go into the BACkground.
    context = LAContext()
    if context.canEvaluatePolicy(.deviceownerAuthentication,error: &error) {
        
        if context.canEvaluatePolicy(.deviceownerAuthentication,error: &error) {

            let reason = "Unlock the Printer app".localize
            context.evaluatePolicy(.deviceownerAuthentication,localizedReason: reason ) { success,error in

                if success {

                    // Move to the main thread because a state update triggers UI changes.
                    dispatchQueue.main.async { [uNowned self] in
                        UIVIEwController.dismiss(animated: true,completion: nil)
                    }

                } else {
                    print(error?.localizedDescription ?? "Failed to authenticate")

                    // fall BACk to a asking for username and password.
                    // ...
                }
            }
        } else {
            print(error?.localizedDescription ?? "Can't evaluate policy")

            // fall BACk to a asking for username and password.
            // ...
        }
    }
    
}
  1. 如您所见,AuthenticationManager 具有反映 UserDefaults 状态的属性,并且基于此值,我会在 2 个位置触发生物识别过程验证。

A) 在 AppDelegate 的存根 applicationWillEnterForeground 中,您可以在这里观察,因此每次我从后台打开应用程序时,它都会被锁定。

   func applicationWillEnterForeground(_ application: UIApplication) {
    if AuthenticationManager.shared.needsAuthentication {
        
        let topController = UIApplication.shared.delegate?.window??.rootVIEwController?.topVIEwController()
        
        let lockedScreen = LockedVC()
        lockedScreen.modalPresentationStyle = .overCurrentContext
        
        topController?.present(lockedScreen,animated: false,completion: nil)
        
    }

B) 从我的应用程序“主页”的 vIEwDIDLoad 开始,基本上与我在 AppDelegate 中的条件逻辑相同(为了该用户将例如强制使用该应用程序)

LockedVC 只是带有一些应用已锁定信息的模糊视图。当生物特征验证成功时,它只会自行关闭,用户会在他离开的页面上。

是否有任何改进此流程的想法或有关后备的任何建议?应用可从 iOS 13.2 获得,所以我想没有配备此 iOS 且没有生物识别功能的设备。

我还没有涉及的是,如果用户没有设置生物特征。然后我想我可以在他想要启用此功能时通知用户他需要设置它的事实,然后允许他更改 UISwitch 的值。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

大佬总结

以上是大佬教程为你收集整理的如何重构 Face/Touch ID 实现? UIKit iOS 13.2+全部内容,希望文章能够帮你解决如何重构 Face/Touch ID 实现? UIKit iOS 13.2+所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。