-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathContentView.swift
117 lines (107 loc) · 4.58 KB
/
ContentView.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import SwiftUI
import LocalAuthentication
import Foundation
import WatchConnectivity
import CareKit
import CareKitUI
import UIKit
struct ContentView: View {
@AppStorage("withdrawalfinal") var withdrawalfinal : Bool = false
@AppStorage("eligibility") var eligibility : Bool = true
@AppStorage("onboarding") var onboarding : Bool = false
@AppStorage("BiometricToggle") var BiometricToggle : Bool = false
@AppStorage("authentication") var authentication : Bool = false
@AppStorage("WatchConnectivity") var WatchConnectivity : Bool = true
@AppStorage("StudyCompletionStatus") var CompletionStatus : Bool = false
@State var isUnlocked = true
func StudyDuration() {
if ProcessInfo.processInfo.systemUptime >= 1300000 {
CompletionStatus = true
}
else {
CompletionStatus = false
}
}
var body: some View {
ZStack {
if CompletionStatus {
CompletionView()
} else {
ZStack {
if isUnlocked {
NavigationStack {
TabView{
CarefeedView()
.tabItem({Image(systemName: "heart.text.square"); Text("Home")})
.toolbarBackground(Color.init(uiColor: .systemGray6), for: .tabBar)
.background(Color(uiColor: .systemGray6), ignoresSafeAreaEdges: .all)
.onAppear(perform: SelectionHaptic)
SimpleHealthDataViews()
.tabItem({Image(systemName: "building" ); Text("Laboratory")})
.toolbarBackground(Color.init(uiColor: .systemGray6), for: .tabBar)
.background(Color(uiColor: .systemGray6), ignoresSafeAreaEdges: .all)
.onAppear(perform: SelectionHaptic)
}
.foregroundColor(.black)
// .fullScreenCover(isPresented: $WatchConnectivity) {
// WatchConnectivityView()
// }
.fullScreenCover(isPresented: $eligibility){
eligibilitystep1()}
.fullScreenCover(isPresented: $withdrawalfinal){
withdrawalconfirmation()
}
}
} else {
BiometricAuthView()
.transition(.slide)
}
}
.ignoresSafeArea()
.onAppear(perform: authenticate)
.onAppear(perform: StudyDuration)
.contentTransition(.opacity)
}
}
}
func SelectionHaptic() {
let Gen = UISelectionFeedbackGenerator()
Gen.selectionChanged()
}
func authenticate() {
let context = LAContext()
var error: NSError?
if BiometricToggle == true { //Is Biometric Authentication Enabled
// check whether biometric authentication is possible
isUnlocked = false
print("Biometric Authentication is enabled")
if context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &error) {
// it's possible, so go ahead and use it
let reason = "Please authenticate to continue"
context.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: reason) { success, authenticationError in
// authentication has now completed
if success {
// authenticated successfully
isUnlocked = true
print("Biometric Authentication Successful")
} else {
// there was a problem
print("Biometric Authentication Unsuccessful")
}
}
} else {
print("Biometric Authentication unavailable")
// no biometrics
}
} else
{
print("Biometric Authentication is disabled")
//Biometrics is not Enabled
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}