mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-19 08:03:50 +02:00
Update PinCodePreferences to include biometrics config
This commit is contained in:
@@ -16,6 +16,7 @@ limitations under the License.
|
||||
|
||||
import Foundation
|
||||
import KeychainAccess
|
||||
import LocalAuthentication
|
||||
|
||||
/// Pin code preferences.
|
||||
@objcMembers
|
||||
@@ -29,6 +30,7 @@ final class PinCodePreferences: NSObject {
|
||||
|
||||
private struct StoreKeys {
|
||||
static let pin: String = "pin"
|
||||
static let biometricsEnabled: String = "biometricsEnabled"
|
||||
}
|
||||
|
||||
static let shared = PinCodePreferences()
|
||||
@@ -49,6 +51,10 @@ final class PinCodePreferences: NSObject {
|
||||
return RiotSettings.shared.forcePinProtection
|
||||
}
|
||||
|
||||
var isBiometricsAvailable: Bool {
|
||||
return LAContext().canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: nil)
|
||||
}
|
||||
|
||||
/// Allowed number of PIN trials before showing forgot help alert
|
||||
let allowedNumberOfTrialsBeforeAlert: Int = 5
|
||||
|
||||
@@ -81,8 +87,60 @@ final class PinCodePreferences: NSObject {
|
||||
}
|
||||
}
|
||||
|
||||
var biometricsEnabled: Bool? {
|
||||
get {
|
||||
do {
|
||||
return try store.object(forKey: StoreKeys.biometricsEnabled) as? Bool
|
||||
} catch let error {
|
||||
NSLog("[PinCodePreferences] Error when reading biometrics enabled from store: \(error)")
|
||||
return nil
|
||||
}
|
||||
} set {
|
||||
do {
|
||||
try store.set(newValue, forKey: StoreKeys.biometricsEnabled)
|
||||
} catch let error {
|
||||
NSLog("[PinCodePreferences] Error when storing biometrics enabled to the store: \(error)")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var isBiometricsSet: Bool {
|
||||
return biometricsEnabled == true
|
||||
}
|
||||
|
||||
func localizedBiometricsName() -> String? {
|
||||
if isBiometricsAvailable {
|
||||
let context = LAContext()
|
||||
switch context.biometryType {
|
||||
case .touchID:
|
||||
return VectorL10n.biometricsModeTouchId
|
||||
case .faceID:
|
||||
return VectorL10n.biometricsModeFaceId
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func biometricsIcon() -> UIImage? {
|
||||
if isBiometricsAvailable {
|
||||
let context = LAContext()
|
||||
switch context.biometryType {
|
||||
case .touchID:
|
||||
return Asset.Images.touchidIcon.image
|
||||
case .faceID:
|
||||
return Asset.Images.faceidIcon.image
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
/// Resets user PIN
|
||||
func reset() {
|
||||
pin = nil
|
||||
biometricsEnabled = nil
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user