Here is my implementation on capturing adpu, where it initailly seems to work.
But then all of a sudden deselected is triggered:
do {
for try await event in session!.eventStream {
switch event {
case .sessionStarted:
print("Session started ... !")
session!.alertMessage = String(localized: "Communicating with device.")
case .readerDetected:
print("Reader detected")
try await session!.startEmulation()
case .readerDeselected:
print("Reader deselected")
await session!.stopEmulation(status: .success)
case .received(let apdu):
do {
print("Received APDU \(apdu)")
let responseAPDU = ProcessAPDU(apdu.payload)
try await apdu.respond(response: responseAPDU)
print("Response APDU successfully sent")
} catch {
print("Error responding to APDU: \(error)")
}
case .sessionInvalidated(let reason):
print("Session invalidated: \(reason)")
session!.alertMessage = String(localized: "Ending communication with device.")
session = nil
@unknown default:
print("Unknown event")
}
}
} catch {
print("Error during event stream: \(error)")
}
Session started ... !
Reader detected
Received APDU {Responded=false, Payload=16 bytes}
.. more back and forth..
Response APDU successfully sent
Reader deselected
default 11:21:42.631634+0100 nfcd -[_NFCardSession sendAPDU:startReadOnCompletion:completion:]:512 Runner
default 11:21:42.631675+0100 nfcd -[_NFCardSession sendAPDU:startReadOnCompletion:completion:]:513 {length = 2, bytes = 0x6a81}
default 11:21:42.632040+0100 nfcd -[_NFCardSession sendAPDU:startReadOnCompletion:completion:]:544 isSent: 1
default 11:21:42.642265+0100 nfcd -[_NFCardSession sendAPDU:startReadOnCompletion:completion:]:512 Runner
default 11:21:42.642335+0100 nfcd -[_NFCardSession sendAPDU:startReadOnCompletion:completion:]:513 {length = 22, bytes = 0xXXXXX}
default 11:21:42.642716+0100 nfcd -[_NFCardSession sendAPDU:startReadOnCompletion:completion:]:544 isSent: 1
default 11:21:42.652183+0100 nfcd -[_NFCardSession sendAPDU:startReadOnCompletion:completion:]:512 Runner
default 11:21:42.652242+0100 nfcd -[_NFCardSession sendAPDU:startReadOnCompletion:completion:]:513 {length = 18, bytes = 0xXXXXX}
default 11:21:42.653002+0100 nfcd -[_NFCardSession sendAPDU:startReadOnCompletion:completion:]:544 isSent: 1
default 11:21:42.670001+0100 nfcd -[_NFCardSession sendAPDU:startReadOnCompletion:completion:]:512 Runner
default 11:21:42.670075+0100 nfcd -[_NFCardSession sendAPDU:startReadOnCompletion:completion:]:513 {length = 18, bytes = 0xXXXXX}
default 11:21:42.670627+0100 nfcd -[_NFCardSession sendAPDU:startReadOnCompletion:completion:]:544 isSent: 1
error 11:21:42.675772+0100 nfcd phOsalNfc_LogStr:65 Rf LinkLoss in DiscMode..
error 11:21:42.676106+0100 nfcd -[_NFCardSession validateReceivedAPDU:]:236 Invalid ISO7816 APDU detected, (null)
default 11:21:42.676153+0100 nfcd -[_NFCardSession sendAPDU:startReadOnCompletion:completion:]:512 Runner
default 11:21:42.676196+0100 nfcd -[_NFCardSession sendAPDU:startReadOnCompletion:completion:]:513 {length = 2, bytes = 0x6a81}
error 11:21:42.676505+0100 nfcd phOsalNfc_LogStr:65 State machine status is NFCSTATUS_REJECTED
error 11:21:42.677401+0100 nfcd NFDriverRemoteDevSend:6531 phLibNfc_RemoteDev_Send failed 0x0038