-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeviceLocalAuthentication.swift
More file actions
65 lines (57 loc) · 1.47 KB
/
DeviceLocalAuthentication.swift
File metadata and controls
65 lines (57 loc) · 1.47 KB
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
55
56
57
58
59
60
61
62
63
64
65
//
// ContentView.swift
// DeviceLocalAuthentication
//
// Created by 墨枫 on 2024/1/12.
//
import SwiftUI
struct ContentView: View {
@State private var isOpenFaceID = false
@StateObject var viewModel = ViewModel()
var body: some View {
//faceIDToggleView
if viewModel.isOpenFaceID {
if !viewModel.isLock {
faceIDLockView
} else {
faceIDToggleView
}
} else {
faceIDToggleView
}
}
private var faceIDToggleView: some View {
HStack {
Text("面容ID登录")
Toggle(isOn: $isOpenFaceID) {
}
}
.padding()
.background(Color(.systemGray6))
.cornerRadius(8)
.padding(.horizontal)
.onChange(of: isOpenFaceID) {
//viewModel.isLock = value
viewModel.isOpenFaceID = isOpenFaceID
}
.onAppear() {
self.isOpenFaceID = viewModel.isOpenFaceID
}
}
private var faceIDLockView: some View {
VStack(spacing: 20) {
Image(systemName: "faceid")
.font(.system(size: 48))
.foregroundColor(.red)
Text("点击进行面容ID登录")
}
.onTapGesture {
viewModel.authenticate()
}
}
}
struct ContentView_Preview: PreviewProvider {
static var previews: some View {
ContentView()
}
}