File tree Expand file tree Collapse file tree 2 files changed +28
-6
lines changed Expand file tree Collapse file tree 2 files changed +28
-6
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ struct StartSessionView: View {
13
13
@ObservedObject var viewModel = StartSessionViewModel ( )
14
14
@Binding var sessionID : String
15
15
@Binding var isPresentingContainerView : Bool
16
+ @State private var showAlert = false
16
17
17
18
var body : some View {
18
19
VStack {
@@ -31,18 +32,34 @@ struct StartSessionView: View {
31
32
dark: . hex( " #7dd6e8 " )
32
33
) ,
33
34
action: {
34
- viewModel. createSession {
35
- sessionID = $0
36
- isPresentingContainerView = true
35
+ viewModel. createSession { sessionId, err in
36
+ if let sessionId = sessionId {
37
+ sessionID = sessionId
38
+ isPresentingContainerView = true
39
+ }
40
+
41
+ showAlert = err != nil
37
42
}
38
43
} ,
39
44
enabled: viewModel. isSignedIn
40
45
)
46
+ . alert ( isPresented: $showAlert) {
47
+ Alert (
48
+ title: Text ( " Error Creating Liveness Session " ) ,
49
+ message: Text ( " Unable to create a liveness session id. Please try again. " ) ,
50
+ dismissButton: . default(
51
+ Text ( " OK " ) ,
52
+ action: {
53
+ isPresentingContainerView = false
54
+ }
55
+ )
56
+ )
57
+ }
41
58
42
59
Spacer ( )
43
60
HStack {
44
61
Spacer ( )
45
- Text ( " v0.1.16 " )
62
+ Text ( " v0.1.19 " )
46
63
. font ( . callout)
47
64
. padding ( )
48
65
}
Original file line number Diff line number Diff line change @@ -25,14 +25,16 @@ class StartSessionViewModel: ObservableObject {
25
25
? . signedIn( action: signOut)
26
26
: . signedOut( action: signIn)
27
27
} catch {
28
+ presentationState = . signedOut( action: signIn)
28
29
print ( " Error fetching auth session " , error)
29
30
}
30
31
31
32
}
32
33
}
33
34
34
- func createSession( _ completion: @escaping ( String ) -> Void ) {
35
+ func createSession( _ completion: @escaping ( String ? , Error ? ) -> Void ) {
35
36
Task { @MainActor in
37
+ let currentPresentationState = presentationState
36
38
presentationState = . loading
37
39
let request = RESTRequest (
38
40
apiName: " liveness " ,
@@ -45,9 +47,12 @@ class StartSessionViewModel: ObservableObject {
45
47
CreateSessionResponse . self,
46
48
from: data
47
49
)
48
- completion ( response. sessionId)
50
+ presentationState = currentPresentationState
51
+ completion ( response. sessionId, nil )
49
52
} catch {
53
+ presentationState = currentPresentationState
50
54
print ( " Error creating session " , error)
55
+ completion ( nil , error)
51
56
}
52
57
}
53
58
}
You can’t perform that action at this time.
0 commit comments