Skip to content

Commit 99d8aa8

Browse files
committed
ios: fix cancellation when setting up screen lock
When you cancel the screen lock setup during auth, the app would get stuck on an empty 'authenticate' screen. We needed to call MobileserverCancelauth instead so the app handles cancellation properly.
1 parent 72774f3 commit 99d8aa8

File tree

1 file changed

+26
-24
lines changed

1 file changed

+26
-24
lines changed

frontends/ios/BitBoxApp/BitBoxApp/BitBoxAppApp.swift

+26-24
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,6 @@ import SwiftUI
99
import Mobileserver
1010
import LocalAuthentication
1111

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-
3212
protocol MessageHandlersProtocol {
3313
func callResponseHandler(queryID: Int, response: String)
3414
func pushNotificationHandler(msg: String)
@@ -53,9 +33,31 @@ class GoEnvironment: NSObject, MobileserverGoEnvironmentInterfaceProtocol, UIDoc
5333
}
5434

5535
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+
}
5961
}
6062
}
6163

@@ -67,7 +69,7 @@ class GoEnvironment: NSObject, MobileserverGoEnvironmentInterfaceProtocol, UIDoc
6769
if !bluetoothManager.isConnected() {
6870
return nil
6971
}
70-
72+
7173
let productInfo = bluetoothManager.parseProduct();
7274
guard let productInfo = productInfo else {
7375
// Not ready or explicitly not connected (waiting for the device to enter

0 commit comments

Comments
 (0)