@@ -33,7 +33,7 @@ public class CardSession {
33
33
}
34
34
35
35
// initial environment to be able to reset a current one
36
- private let _environment : SessionEnvironment
36
+ private var _environment : SessionEnvironment
37
37
public internal( set) var environment : SessionEnvironment
38
38
39
39
private let reader : CardReader
@@ -350,6 +350,7 @@ public class CardSession {
350
350
351
351
private func sessionDidStop( completion: ( ( ) -> Void ) ? ) {
352
352
nfcReaderSubscriptions = [ ]
353
+ resetEnvironment ( )
353
354
preflightReadMode = . fullCardRead
354
355
sendSubscription = [ ]
355
356
viewDelegate. sessionStopped ( completion: completion)
@@ -422,7 +423,7 @@ public class CardSession {
422
423
case . preflightFiltered:
423
424
self . viewDelegate. wrongCard ( message: error. localizedDescription)
424
425
// We have to return environment to initial state to reset all the changes
425
- self . environment = self . _environment
426
+ self . resetEnvironment ( )
426
427
DispatchQueue . global ( ) . asyncAfter ( deadline: . now( ) + 2 ) {
427
428
guard self . reader. isReady else {
428
429
onSessionStarted ( self , . userCancelled)
@@ -584,6 +585,11 @@ public class CardSession {
584
585
resetCodesController!. cardIdDisplayFormat = config. cardIdDisplayFormat
585
586
resetCodesController!. start ( codeType: type, cardId: cardId, completion: completion)
586
587
}
588
+
589
+ private func resetEnvironment( ) {
590
+ _environment. resetCodes ( )
591
+ environment = _environment
592
+ }
587
593
}
588
594
//MARK: - JSON RPC
589
595
extension CardSession {
@@ -596,7 +602,10 @@ extension CardSession {
596
602
do {
597
603
request = try JSONRPCRequest ( jsonString: jsonRequest)
598
604
let runnable = try jsonConverter. convert ( request: request)
599
- runnable. run ( in: self ) { completion ( $0. toJsonResponse ( id: request. id) . json) }
605
+ runnable. run ( in: self ) {
606
+ completion ( $0. toJsonResponse ( id: request. id) . json)
607
+ self . resetEnvironment ( )
608
+ }
600
609
} catch {
601
610
completion ( error. toJsonResponse ( id: request? . id) . json)
602
611
}
0 commit comments