- iOS 9.0+
- Xcode 9.4+
- Swift 4.1+
CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:
$ gem install cocoapods
To integrate GABiometricAuthentication into your Xcode project using CocoaPods, specify it in your Podfile:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '10.0'
use_frameworks!
target '<Your Target Name>' do
pod 'GABiometricAuthentication'
end
Then, run the following command:
$ pod install
import "GABiometricAuthentication", then create GAFullScreenConfiguration and call to the function openRegisterForBiometricAuthentication with type "fullScrrenUI" in the GABiometricAuthentication class
import GABiometricAuthentication
let uiconfiguration = GAFullScreenUIConfiguration(titleText: NSAttributedString(string: "title"), descriptionText: NSAttributedString(string: "description"), backgroundColor: .white, centerImage: UIImage(named: "touch-id"), allowButtonConfiguration: GAFullScreenButtonConfiguration(backgroundColor: .black, textColor: .white, text: "Allow"), dontAllowButtonConfiguration: GAFullScreenButtonConfiguration(backgroundColor: .black, textColor: .white, text: "Do not Allow"))
let configuration = GAFullScreenConfiguration(uiConfiguration: uiconfiguration, localizedReason: "enter for password") { (result) in
}
GABiometricAuthentication.openRegisterForBiometricAuthentication(usingRegisterType: .fullScrrenUI(configuration), inViewController: self)
Create object/view that implement CustomPopupUI
import GABiometricAuthentication
class MyCustomPopupView: UIView,CustomPopupUI
{
var continerView: UIView
{
return self
}
// MARK: - IBOutlet
@IBOutlet weak var allowButton : UIButton! // subview of continerView
@IBOutlet weak var doNotAllowButton : UIButton! // subview of continerView
}
Then create GACustomPopupConfiguration and pass the CustomPopupUI object using "GACustomPopupUIConfiguration".
let customPopupUI = MyCustomPopupView(frame: CGRect.zero)
let uiconfiguration = GACustomPopupUIConfiguration(customPopupUI: customPopupUI, popupSize: CGSize(width: 309.0, height: 284.0))
let configuration = GACustomPopupConfiguration(uiConfiguration: uiconfiguration, localizedReason: "enter for password") { (result) in
}
To show the registration popup call to the function openRegisterForBiometricAuthentication with type customUI in the GABiometricAuthentication class
GABiometricAuthentication.openRegisterForBiometricAuthentication(usingRegisterType: .customUI(configuration), inViewController: self)
call to evaluateBiometricLocalAuthentication in GABiometricAuthentication. pass to the function the localizedReason for using the biometric authentication and the results block
GABiometricAuthentication.evaluateBiometricLocalAuthentication(localizedReason: "showPassword") { [weak self] (result) in
guard let strongSelf = self else { return }
switch result
{
case .success : strongSelf.resultLabel.text = "success"
default : strongSelf.resultLabel.text = "failed"
}
}
if the user try more then the available number of tries the system will lock the biometric local authentication, to unlock it call to unlockBiometricLocalAuthentication in GABiometricAuthentication
GABiometricAuthentication.unlockBiometricLocalAuthentication(byLocalizedReason: "Access your password") { [weak self] (result) in
guard let strongSelf = self else { return }
switch result
{
case true : strongSelf.resultLabel.text = "success"
case false : strongSelf.resultLabel.text = ""
}
}
to check if user can use biometric local authentication
let canUseBiometric = GABiometricAuthentication.canEvaluatePolicyDeviceOwnerAuthenticationWithBiometrics()