Skip to content

Commit 1f114f5

Browse files
committed
Fix NFCConnection to support the new connections semantics
1 parent 4544037 commit 1f114f5

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

YubiKit/YubiKit/NFCSmartCardConnection.swift

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -226,21 +226,22 @@ private final actor NFCConnectionManager: NSObject {
226226
throw NFCConnectionError.unsupported
227227
}
228228

229-
// To proceed with a new connection we need to acquire a lock
230-
guard !isEstablishing else { throw ConnectionError.cancelled }
231-
defer { isEstablishing = false }
232-
isEstablishing = true
233-
234-
// Close the previous connection before establishing a new one
229+
// if there is already a connection for this slot we throw `ConnectionError.busy`.
230+
// The caller must close the connection first.
235231
switch currentState {
236232
case .inactive:
237233
// lets continue
238234
break
239235
case .scanning, .connected:
240-
// invalidate and continue
241-
await invalidate()
236+
// throw
237+
throw ConnectionError.busy
242238
}
243239

240+
// To proceed with a new connection we need to acquire a lock
241+
guard !isEstablishing else { throw ConnectionError.cancelled }
242+
defer { isEstablishing = false }
243+
isEstablishing = true
244+
244245
// Start polling
245246
guard let session = NFCTagReaderSession(pollingOption: [.iso14443], delegate: self, queue: nil) else {
246247
throw NFCConnectionError.failedToPoll

0 commit comments

Comments
 (0)