@@ -9,26 +9,6 @@ import SwiftUI
9
9
import Mobileserver
10
10
import LocalAuthentication
11
11
12
- func authenticateUser( completion: @escaping ( Bool ) -> Void ) {
13
- let context = LAContext ( )
14
- var error : NSError ?
15
-
16
- if context. canEvaluatePolicy ( . deviceOwnerAuthentication, error: & error) {
17
- // TODO: localize the reason string.
18
- let reason = " Authentication required "
19
- context. evaluatePolicy ( . deviceOwnerAuthentication, localizedReason: reason) { success, authenticationError in
20
- DispatchQueue . main. async {
21
- completion ( success)
22
- }
23
- }
24
- } else {
25
- // Biometric authentication not available
26
- DispatchQueue . main. async {
27
- completion ( false )
28
- }
29
- }
30
- }
31
-
32
12
protocol MessageHandlersProtocol {
33
13
func callResponseHandler( queryID: Int , response: String )
34
14
func pushNotificationHandler( msg: String )
@@ -53,9 +33,31 @@ class GoEnvironment: NSObject, MobileserverGoEnvironmentInterfaceProtocol, UIDoc
53
33
}
54
34
55
35
func auth( ) {
56
- authenticateUser { success in
57
- // TODO: enabling auth but entering wrong passcode does not remove auth screen
58
- MobileserverAuthResult ( success)
36
+ let context = LAContext ( )
37
+ var error : NSError ?
38
+
39
+ if context. canEvaluatePolicy ( . deviceOwnerAuthentication, error: & error) {
40
+ // TODO: localize the reason string.
41
+ let reason = " Authentication required "
42
+ context. evaluatePolicy ( . deviceOwnerAuthentication, localizedReason: reason) { success, authenticationError in
43
+ DispatchQueue . main. async {
44
+ if success {
45
+ MobileserverAuthResult ( true ) ;
46
+ } else {
47
+ if let laError = authenticationError as? LAError ,
48
+ laError. code == . userCancel {
49
+ MobileserverCancelAuth ( ) ;
50
+ } else {
51
+ MobileserverAuthResult ( false ) ;
52
+ }
53
+ }
54
+ }
55
+ }
56
+ } else {
57
+ // Biometric authentication not available
58
+ DispatchQueue . main. async {
59
+ MobileserverAuthResult ( false ) ;
60
+ }
59
61
}
60
62
}
61
63
@@ -67,7 +69,7 @@ class GoEnvironment: NSObject, MobileserverGoEnvironmentInterfaceProtocol, UIDoc
67
69
if !bluetoothManager. isConnected ( ) {
68
70
return nil
69
71
}
70
-
72
+
71
73
let productInfo = bluetoothManager. parseProduct ( ) ;
72
74
guard let productInfo = productInfo else {
73
75
// Not ready or explicitly not connected (waiting for the device to enter
0 commit comments