You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

98 lines
3.9 KiB

  1. //
  2. // BiometricAuthenticationWireframe.swift
  3. // GME Remit
  4. //
  5. // Created by InKwon Kim on 30/03/2019.
  6. //Copyright © 2019 Gobal Money Express Co. Ltd. All rights reserved.
  7. //
  8. import UIKit
  9. import LocalAuthentication
  10. class BiometricAuthenticationWireframe {
  11. weak var view: UIViewController!
  12. var completion: ((String?) -> ())?
  13. var information: String?
  14. }
  15. extension BiometricAuthenticationWireframe: BiometricAuthenticationWireframeInput {
  16. var storyboardName: String {return "BiometricAuthentication"}
  17. func getMainView() -> UIViewController {
  18. let service = BiometricAuthenticationService()
  19. let interactor = BiometricAuthenticationInteractor(service: service)
  20. let presenter = BiometricAuthenticationPresenter()
  21. let viewController = viewControllerFromStoryboard(of: BiometricAuthenticationViewController.self)
  22. viewController.presenter = presenter
  23. interactor.output = presenter
  24. presenter.interactor = interactor
  25. presenter.wireframe = self
  26. presenter.information = information
  27. presenter.view = viewController
  28. self.view = viewController
  29. return viewController
  30. }
  31. func showAuthentication() {
  32. let context = LAContext()
  33. var error: NSError?
  34. let msg = "Confirm your fingerprint or face to authenticate."
  35. let deviceAuth = LAPolicy.deviceOwnerAuthentication
  36. if context.canEvaluatePolicy(deviceAuth, error: &error) {
  37. context.evaluatePolicy(deviceAuth, localizedReason: msg, reply: { (success, err) in
  38. if success {
  39. DispatchQueue.main.async {
  40. self.completion?(nil)
  41. }
  42. } else {
  43. let message: String
  44. if #available(iOS 11.0, *) {
  45. switch err {
  46. case LAError.authenticationFailed?:
  47. message = "There was a problem verifying your identity."
  48. case LAError.userCancel?:
  49. message = "You pressed cancel."
  50. case LAError.userFallback?:
  51. message = "You pressed password."
  52. case LAError.biometryNotAvailable?:
  53. message = "Face ID/Touch ID is not available."
  54. case LAError.biometryNotEnrolled?:
  55. message = "Face ID/Touch ID is not set up."
  56. case LAError.biometryLockout?:
  57. message = "Face ID/Touch ID is locked."
  58. default:
  59. message = "Face ID/Touch ID may not be configured"
  60. }
  61. } else {
  62. switch err {
  63. case LAError.authenticationFailed?:
  64. message = "There was a problem verifying your identity."
  65. case LAError.userCancel?:
  66. message = "You pressed cancel."
  67. case LAError.userFallback?:
  68. message = "You pressed password."
  69. case LAError.touchIDNotAvailable?:
  70. message = "Face ID/Touch ID is not available."
  71. case LAError.touchIDNotEnrolled?:
  72. message = "Face ID/Touch ID is not set up."
  73. case LAError.touchIDLockout?:
  74. message = "Face ID/Touch ID is locked."
  75. default:
  76. message = "Face ID/Touch ID may not be configured"
  77. }
  78. }
  79. self.completion?(message)
  80. }
  81. })
  82. } else {
  83. completion?(error?.localizedDescription)
  84. }
  85. }
  86. }