Skip to content

Commit e879e4b

Browse files
authored
Merge pull request #2 from MultiColourPixel/main
Allow consumers to check if device is attached
2 parents ba96f13 + 781420a commit e879e4b

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

LibFido2Swift/Sources/LibFido2Swift/LibFido2Swift.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,15 @@ public class FIDO2 {
6666

6767
public init() {}
6868

69+
public func hasDeviceAttached() -> Bool {
70+
do {
71+
let _ = try findFirstDevicePath()
72+
return true
73+
} catch {
74+
return false
75+
}
76+
}
77+
6978
public func deviceHasPin() throws -> Bool {
7079
let devPath = try findFirstDevicePath()
7180

LibFido2TestApp/ContentView.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ struct ContentView: View {
1616
@AppStorage("origin") var origin = ""
1717
@AppStorage("devicePin") var devicePin = ""
1818
@State var responseJson = ""
19+
@State private var isDevicePresent = false
20+
@State private var isDevicePresentAlertShown = false
1921
var body: some View {
2022
VStack {
2123
VStack {
@@ -33,6 +35,17 @@ struct ContentView: View {
3335
}
3436
}
3537
}
38+
Button("Is Device Present?") {
39+
isDevicePresent = fido2.hasDeviceAttached()
40+
isDevicePresentAlertShown = true
41+
}
42+
.alert(isPresented: $isDevicePresentAlertShown) {
43+
Alert(
44+
title: Text("Device is \(isDevicePresent ? "present" : "not present")"),
45+
message: nil,
46+
dismissButton: .default(Text("OK"))
47+
)
48+
}
3649
Button("Cancel") {
3750
fido2.cancel()
3851
}

0 commit comments

Comments
 (0)