从哪里致电触摸ID逻辑



我是iOS的新手。我正在应用程序中尝试一个本地身份验证框架。我的应用程序流就像用户打开应用程序时,他能够看到Splash屏幕,然后,如果他是新用户,他将重定向到登录屏幕,然后转到仪表板屏幕。从登录名中,如果他单击记住我,下次用户打开应用程序时,他将直接重定向到仪表板。

我只是不明白我在哪个屏幕上添加authenticationWithTouchID逻辑。在App Open上,我想显示TouchID弹出窗口,以便用户可以对仪表板进行身份验证并重定向。

更新:1

我正在检查记住我在AppDelegatedidFinishLaunchingWithOptions()中是True还是不,因此,我曾经打开特定的UIViewController。因此,在相同的方法中,我只检查启用用户的触摸ID,如果用户对触摸ID进行了身份验证,则我显示弹出窗口其他正常将其重定向到仪表板。这是一种适当的方法吗?我想问的还有一件事是,暂停应用程序单击"主页"按钮以及当应用重新打开该身份验证方法时,我想再次显示触摸ID。它会转到applicationWillEnterForeground()吗?

更新:2

当触摸ID使用applicationWillEnterForeground()

打开时,仪表板内容在后台看到了

根据我的经验,您需要将两者分开 authentication相关和其他UIViewController代码。我建议 为Bio-Matric authentication创建基于块的singleton类 (触摸和faceid(

参考您的参考,请参阅基于可怕的块身份验证库生物特征仪。

我建议将所有与身份验证相关的代码保存到Login屏幕中。

请参阅下面的自动登录代码。

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    if isRemmberMe{
        BioMetricAuthenticator.authenticateWithBioMetrics(reason: "") { (result) in
            switch result {
            case .success( _):
                print("Redirect into dashboard screen")
            case .failure(let error):
                print("Authentication Failed")
            }
        }
    }
}

如果您采用这种方法,则无需在 AppDelegate.swift文件由于您的rootViewController总是 登录屏幕。只需从中设置您的初始控制器登录屏幕 storyboard

更新:1

问题:它是一种正确的方法吗?

是的,这是一种正确的方法,但是 牢记生物介绍的身份验证。

问题:如果应用程序状态更改

,我该如何管理触摸IDID或FACEID管理

您可以使用applicationWillEnterForegroundapplicationDidBecomeActive如果更改了应用程序状态。一 更多,我想提到两种方法也称为 当用户刚打开应用程序时。如果要完全限制用户访问应用程序内容,则使用applicationWillEnterForeground(),否则可以使用applicationDidBecomeActive

使用

更新:2

如果要限制应用程序内容,则需要手动添加虚拟模糊UIView

代码:

let blurEffect = UIBlurEffect(style: .Light)
let blurVisualEffectView = UIVisualEffectView(effect: blurEffect)
blurVisualEffectView.frame = view.bounds
self.view.addSubview(blurVisualEffectView)

删除是否成功

blurVisualEffectView.removeFromSuperview()

如果您的用户已经登录,在您的UserDefaults中保存,然后继续进行应用程序启动如下:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.
    self.window = UIWindow(frame: UIScreen.main.bounds)
    if !isLoggedIn {
        let loginController = LoginController()
        self.window?.rootViewController = loginController
        self.window?.makeKeyAndVisible()
        return true
    }
    let authController = AuthenticaeController()
    self.window?.rootViewController = authController
    self.window?.makeKeyAndVisible()
    return true
}

iSloggedIn bool应该是您从UserDefaults中存储的值。

您已将true存储在userDefault中,其中用户成功登录

例如。 UserDefaults.standard.setValue("true", forKey: "isLogin")

AppDelegate.Swift

 func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        let islogin = UserDefaults.standard.bool(forKey: "isLogin")
        if islogin
        {
           self.NextViewController(storybordid: "DashBoardViewIdentifier")
        }
        else
        {
            self.NextViewController(storybordid: "LoginViewIdentifier")
        }
        return true
    }

,还可以在AppDelegate.swift中创建method

   func NextViewController(storybordid:String)
    {
        let storyBoard:UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
        let exampleVC = storyBoard.instantiateViewController(withIdentifier:storybordid )
        let nav = UINavigationController(rootViewController: exampleVC)
        nav.navigationController?.setNavigationBarHidden(true, animated: false)
        self.window = UIWindow(frame: UIScreen.main.bounds)
        self.window?.rootViewController = nav
        self.window?.makeKeyAndVisible()
    }

最新更新