File tree Expand file tree Collapse file tree 2 files changed +22
-0
lines changed
LibFido2Swift/Sources/LibFido2Swift Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments