iOS cancel TouchID authentication dialog programmatically

前端 未结 2 974
广开言路
广开言路 2021-02-20 12:01

Is it possible to cancel the TouchID alert dialog programmatically after the LAContext.evaluatePolicy call? If yes: how?

2条回答
  •  故里飘歌
    2021-02-20 12:20

    In my case, I find out why it not working because the LAContext instance I try to invalidate() is not the same instance who I call evaluatePolicy().

    So You need to make sure that all ViewControllers shared the same instance. swift 4

    public class MyBiometryUtility: NSObject {
    static private var sharedBiometry: MyBiometryUtility? = nil
    var context: LAContext = LAContext()
    @objc public static func sharedInstance() -> MyBiometryUtility{
            if let sharedBiometry = sharedBiometry {
                return sharedBiometry;
            } else{
                sharedBiometry = MyBiometryUtility()
                return sharedBiometry!
            }
        }
    public func tryBiometryAuth() { ... }
    public func closeBiometryAuth() {... }
    

    In SomeViewController.swift

    func buttonTapped(sender: Any){
        // show dialog.
        MyBiometryUtility.sharedInstance().tryBiometryAuth()
    }
    func timerCountDown(){
        // close dialog.
        if tooLong() {
            MyBiometryUtility.sharedInstance().closeBiometryAuth()
        }
    }
    

提交回复
热议问题