File tree Expand file tree Collapse file tree 4 files changed +64
-21
lines changed
Expand file tree Collapse file tree 4 files changed +64
-21
lines changed Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ import LocalAuthentication
77public enum AuthResult {
88 case success
99 case canceled
10- case unavailable
10+ case unavailable( String )
1111 case failed
1212}
1313
@@ -29,7 +29,20 @@ public enum AuthService {
2929
3030 var error : NSError ?
3131 guard context. canEvaluatePolicy ( . deviceOwnerAuthentication, error: & error) else {
32- completion ( . unavailable)
32+ var message = " Device authentication is not available. "
33+
34+ let biometryType = context. biometryType
35+ if biometryType == . none {
36+ message += " Please enable Face ID, Touch ID, or set up a device passcode in Settings. "
37+ } else if biometryType == . faceID {
38+ message += " Face ID is not available. Please set up a device passcode in Settings. "
39+ } else if biometryType == . touchID {
40+ message += " Touch ID is not available. Please set up a device passcode in Settings. "
41+ }
42+
43+ DispatchQueue . main. async {
44+ completion ( . unavailable( message) )
45+ }
3346 return
3447 }
3548
Original file line number Diff line number Diff line change @@ -326,20 +326,22 @@ struct LoopAPNSBolusView: View {
326326
327327 private func authenticateAndSendInsulin( ) {
328328 AuthService . authenticate ( reason: " Confirm your identity to send insulin. " ) { result in
329- switch result {
330- case . success:
331- sendInsulinConfirmed ( )
332- case . unavailable:
333- alertMessage = " Authentication not available "
334- alertType = . error
335- showAlert = true
336- case . failed:
337- alertMessage = " Authentication failed "
338- alertType = . error
339- showAlert = true
340- case . canceled:
341- // User canceled: no alert to avoid spammy UX
342- break
329+ DispatchQueue . main. async {
330+ switch result {
331+ case . success:
332+ self . sendInsulinConfirmed ( )
333+ case let . unavailable( message) :
334+ self . alertMessage = message
335+ self . alertType = . error
336+ self . showAlert = true
337+ case . failed:
338+ self . alertMessage = " Authentication failed "
339+ self . alertType = . error
340+ self . showAlert = true
341+ case . canceled:
342+ // User canceled: no alert to avoid spammy UX
343+ break
344+ }
343345 }
344346 }
345347 }
Original file line number Diff line number Diff line change @@ -113,8 +113,22 @@ struct BolusView: View {
113113 message: Text ( " Are you sure you want to send \( InsulinFormatter . shared. string ( bolusAmount) ) U? " ) ,
114114 primaryButton: . default( Text ( " Confirm " ) , action: {
115115 AuthService . authenticate ( reason: " Confirm your identity to send bolus. " ) { result in
116- if case . success = result {
117- sendBolus ( )
116+ DispatchQueue . main. async {
117+ switch result {
118+ case . success:
119+ self . sendBolus ( )
120+ case let . unavailable( message) :
121+ self . alertMessage = message
122+ self . alertType = . validation
123+ self . showAlert = true
124+ case . failed:
125+ self . alertMessage = " Authentication failed "
126+ self . alertType = . validation
127+ self . showAlert = true
128+ case . canceled:
129+ // User canceled, no alert
130+ break
131+ }
118132 }
119133 }
120134 } ) ,
Original file line number Diff line number Diff line change @@ -196,12 +196,26 @@ struct MealView: View {
196196 DispatchQueue . main. asyncAfter ( deadline: . now( ) + 0.1 ) {
197197 if bolusAmount > 0 {
198198 AuthService . authenticate ( reason: " Confirm your identity to send bolus. " ) { result in
199- if case . success = result {
200- sendMealCommand ( )
199+ DispatchQueue . main. async {
200+ switch result {
201+ case . success:
202+ self . sendMealCommand ( )
203+ case let . unavailable( message) :
204+ self . alertMessage = message
205+ self . alertType = . validationError
206+ self . showAlert = true
207+ case . failed:
208+ self . alertMessage = " Authentication failed "
209+ self . alertType = . validationError
210+ self . showAlert = true
211+ case . canceled:
212+ // User canceled, no alert
213+ break
214+ }
201215 }
202216 }
203217 } else {
204- sendMealCommand ( )
218+ self . sendMealCommand ( )
205219 }
206220 }
207221 } ) ,
You can’t perform that action at this time.
0 commit comments