-
Notifications
You must be signed in to change notification settings - Fork 0
/
FaceIDLogin.swift
54 lines (46 loc) · 1.33 KB
/
FaceIDLogin.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//
// ContentView.swift
// PinLogin
//
// Created by Antonio Castaldo on 10/12/21.
//
// Aggiungere Privacy a Info.plist
import SwiftUI
import LocalAuthentication
struct FaceIDLogin: View {
@State private var isUnlocked = false
func authenticate() {
let context = LAContext()
var error: NSError?
// check whether biometric authentication is possible
if context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &error) {
// it's possible, so go ahead and use it
let reason = "We need to unlock your data."
context.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: reason) { success, authenticationError in
// authentication has now completed
if success {
isUnlocked = true
} else {
// there was a problem
}
}
} else {
// no biometrics
}
}
var body: some View {
VStack {
if isUnlocked {
Text("Unlocked")
} else {
Text("Locked")
}
}
.onAppear(perform: authenticate)
}
}
struct FaceIDLoginPreview: PreviewProvider {
static var previews: some View {
FaceIDLogin()
}
}