diff --git a/CHANGELOG.md b/CHANGELOG.md index e255c9d..b19cf30 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +### 0.3.9 + +- **Add**: `allowableReuseDuration` variable to `BiometricsService` which is a wrapper for touchIDAuthenticationAllowableReuseDuration. +- **Add**: individual `isTouchIdSupported` variable to `BiometricsService` to indicate if TouchId can be used. +- **Add**: `clear` function to `BiometricsService` so the context can be refreshed. +- **Update**: Documentations. + ### 0.3.8 - **Fixed**: `SwiftValidator` fork moved to TouchInstinct repo, the used one is removed. Version number is downgraded to `4.0.2` to avoid collision when the original pod will update. diff --git a/LeadKitAdditions.podspec b/LeadKitAdditions.podspec index 91a0be4..e88b912 100644 --- a/LeadKitAdditions.podspec +++ b/LeadKitAdditions.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "LeadKitAdditions" - s.version = "0.3.8" + s.version = "0.3.9" s.summary = "iOS framework with a bunch of tools for rapid development" s.homepage = "https://github.com/TouchInstinct/LeadKitAdditions" s.license = "Apache License, Version 2.0" diff --git a/Sources/Services/BiometricsService.swift b/Sources/Services/BiometricsService.swift index 37ee7f0..83fa2c6 100644 --- a/Sources/Services/BiometricsService.swift +++ b/Sources/Services/BiometricsService.swift @@ -29,13 +29,35 @@ public final class BiometricsService { private lazy var laContext = LAContext() - /// Returns true if user can authenticate via faceID + /// If the user unlocks the device using biometrics within the specified time interval, + /// then authentication for the receiver succeeds automatically, without prompting the user for biometrics. + /// Works only after device unlock event, no other apps authentications counts. + public var allowableReuseDuration: TimeInterval? = nil { + didSet { + guard let duration = allowableReuseDuration else { + return + } + if #available(iOS 9.0, *) { + laContext.touchIDAuthenticationAllowableReuseDuration = duration + } + } + } + + /// Returns true if user can authenticate via Face ID public var isFaceIdSupported: Bool { if #available(iOS 11.0, *) { return canAuthenticateWithBiometrics && laContext.biometryType == .faceID - } else { - return false } + return false + } + + /// Returns true if user can authenticate via Touch ID + public var isTouchIdSupported: Bool { + let canEvaluate = canAuthenticateWithBiometrics + if #available(iOS 11.0, *) { + return canEvaluate && laContext.biometryType == .touchID + } + return canEvaluate } /// Returns current domain state @@ -45,19 +67,22 @@ public final class BiometricsService { return laContext.evaluatedPolicyDomainState } - /// Indicates is it possible to authenticate on this device via touch id + /// Indicates is it possible to authenticate on this device via any biometric. + /// Returns false if not enrolled or lockedout. public var canAuthenticateWithBiometrics: Bool { return laContext.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: nil) } /** - Initiates system biometrics authentication process + Initiates system biometrics authentication process. + Once evaluated, will return success until the context is deallocated. + Call "clear" to use a new context instance. - - parameters: - - description: prompt on the system alert - - fallback: alternative action button title on system alert - - cancel: cancel button title on the system alert - - authHandler: callback, with parameter, indicates if user authenticate successfuly + - parameters: + - description: prompt on the system alert + - fallback: alternative action button title on system alert + - cancel: cancel button title on the system alert + - authHandler: callback, with parameter, indicates if user authenticate successfuly */ public func authenticateWithBiometrics(with description: String, fallback fallbackTitle: String?, @@ -73,6 +98,10 @@ public final class BiometricsService { } } - public init() {} + /// Replace old instance of the context with the new one + public func clear() { + laContext = LAContext() + } + public init() {} }