diff --git a/TangemSdk/TangemSdk/Common/Core/CardSession.swift b/TangemSdk/TangemSdk/Common/Core/CardSession.swift index ba5811bea..7f382f31b 100644 --- a/TangemSdk/TangemSdk/Common/Core/CardSession.swift +++ b/TangemSdk/TangemSdk/Common/Core/CardSession.swift @@ -319,6 +319,8 @@ public class CardSession { /// We need to remember the tag for the duration of the command to be able to compare this tag with new one on tag from connected/lost events func rememberTag() { + guard case .tag = reader.tag.value else { return } + currentTag = reader.tag.value } diff --git a/TangemSdk/TangemSdk/Operations/Command.swift b/TangemSdk/TangemSdk/Operations/Command.swift index b560fec38..c026b73d5 100644 --- a/TangemSdk/TangemSdk/Operations/Command.swift +++ b/TangemSdk/TangemSdk/Operations/Command.swift @@ -91,18 +91,17 @@ extension Command { private func transceiveInternal(in session: CardSession, completion: @escaping CompletionResult) { do { - session.rememberTag() - Log.apdu("C-APDU serialization start".titleFormatted) let commandApdu = try serialize(with: session.environment) Log.apdu("C-APDU serialization finish".titleFormatted) - + + session.rememberTag() + transceive(apdu: commandApdu, in: session) { result in - session.releaseTag() switch result { case .success(let responseApdu): do { - + session.releaseTag() Log.apdu("R-APDU deserialization start".titleFormatted) let responseData = try self.deserialize(with: session.environment, from: responseApdu) Log.apdu("R-APDU deserialization finish".titleFormatted) @@ -129,11 +128,13 @@ extension Command { self.requestPin(.passcode, session, completion: completion) } else { fallthrough } default: + session.releaseTag() completion(.failure(error)) } } } } catch { + session.releaseTag() completion(.failure(error.toTangemSdkError())) } } @@ -235,6 +236,7 @@ extension Command { session.resume() self.transceiveInternal(in: session, completion: completion) case .failure(let error): + session.releaseTag() completion(.failure(error)) } }