This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | /// Variable Declaration(s) | |
| class var isFaceIdAvailable: Bool { | |
| let context: LAContext = LAContext() | |
| let evaluate = context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: nil) | |
| if #available(iOS 11.0, *) { | |
| return (context.biometryType == .faceID) | |
| } | |
| return evaluate | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | /// Change default message as per your need. | |
| fileprivate static var defaultReasonMessage: String { | |
| return LocalAuthentication.isFaceIdAvailable ? kFaceIdAuthenticationReason : kTouchIdAuthenticationReason | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | let kReasonMessage = "Biometeric required your authentication." | |
| /// Biometric Default Reason(s) | |
| let kBiometryNotAvailableReason = "Biometric authentication is not available for this device." | |
| /// Common Message(s) | |
| let kSetPasscode = "Please set device passcode for authentication." | |
| /// TouchID Related Message(s) | |
| let kTouchIdAuthenticationReason = "Confirm your fingerprint to authenticate." | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | import LocalAuthentication | |
| /// AuthenticationBlockState | |
| enum AuthenticationBlockState { | |
| case success | |
| case failed | |
| case canceledByUser | |
| case fallback | |
| case canceledBySystem | |
| case passcodeNotSet | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | /// Block Declaration(s) | |
| typealias authenticationBlock = ((AuthenticationBlockState) -> ()) | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | class func authenticateUserWithBioMetrics(_ reasonMessage: String, cancelTitle: String? = "", block: @escaping authenticationBlock) { | |
| let context: LAContext = LAContext() | |
| context.localizedCancelTitle = cancelTitle | |
| context.localizedFallbackTitle = "Passcode" | |
| evaluate(.deviceOwnerAuthentication, reason: (reasonMessage.isEmpty ? defaultReasonMessage : reasonMessage), context: context, block: block) | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | fileprivate static func evaluate(_ policy: LAPolicy, reason: String, context: LAContext, block: @escaping authenticationBlock) { | |
| context.evaluatePolicy(policy, localizedReason: reason) { (isSuccess, error) in | |
| block(AuthenticationBlockState.initWith(error as? LAError)) | |
| } | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | /// LocalAuthentication | |
| class LocalAuthentication: NSObject { | |
| /// Variable Declaration(s) | |
| class var isFaceIdAvailable: Bool { | |
| let context: LAContext = LAContext() | |
| let evaluate = context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: nil) | |
| if #available(iOS 11.0, *) { | |
| return (context.biometryType == .faceID) | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | /// Variable Declaration(s) | |
| var lblTitle: UILabel = { | |
| var lbl: UILabel = UILabel() | |
| lbl.translatesAutoresizingMaskIntoConstraints = false | |
| lbl.backgroundColor = .clear | |
| lbl.textAlignment = .center | |
| lbl.adjustsFontSizeToFitWidth = true | |
| lbl.minimumScaleFactor = 0.75 | |
| lbl.textColor = .darkText | |
| lbl.font = .boldSystemFont(ofSize: UIFont.systemFontSize) | 
OlderNewer