GABiometricAuthentication 2.1.0

GABiometricAuthentication 2.1.0

Ido Meirov 维护。



  • idoMeirov

Markdownify
GABiometricAuthentication

为您的CollectionView添加无限滚动功能。

Sponsor Version Author Swift Swift

目录

  1. 要求
  2. 安装
  3. 如何使用

要求

  • iOS 9.0+
  • Xcode 9.4+
  • Swift 4.1+

安装

CocoaPods

CocoaPods 是 Cocoa 项目的依赖管理工具。您可以使用以下命令安装它

$ gem install cocoapods

要使用 CocoaPods 将 GABiometricAuthentication 集成到您的 Xcode 项目中,在 Podfile 中指定它

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '10.0'
use_frameworks!

target '<Your Target Name>' do
  pod 'GABiometricAuthentication'
end

然后,运行以下命令

$ pod install

如何使用

打开注册弹出窗口

选项 1 使用默认尺寸

导入 "GABiometricAuthentication",然后创建 GAFullScreenConfiguration 并在 GABiometricAuthentication 类中调用 openRegisterForBiometricAuthentication 函数,并将类型设置为 "fullScrrenUI"。

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)

选项 2 自定义 UI

创建实现 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
}

然后创建 GACustomPopupConfiguration 并通过 "GACustomPopupUIConfiguration" 传递 CustomPopupUI 对象。

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

}
        

要显示注册弹出窗口,请在 GABiometricAuthentication 类中调用 openRegisterForBiometricAuthentication 函数,并将类型设置为 customUI。

GABiometricAuthentication.openRegisterForBiometricAuthentication(usingRegisterType: .customUI(configuration), inViewController: self)

切换进入生物识别本地认证

在 GABiometricAuthentication 中调用 evaluateBiometricLocalAuthentication。传递本地化和使用生物识别认证的理由以及结果块到该函数。

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"
   }
}

解锁生物识别本地认证

如果用户尝试次数超过可用的次数,系统将锁定生物识别本地身份验证,要解锁它请调用GABiometricAuthentication中的unlockBiometricLocalAuthentication。

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 = ""
   }
           
}

检查生物识别本地身份验证是否可用

用于检查用户是否可以使用生物识别本地身份验证

let canUseBiometric = GABiometricAuthentication.canEvaluatePolicyDeviceOwnerAuthenticationWithBiometrics()