-[_NFCardSession validateReceivedAPDU:]:236 Invalid ISO7816 APDU detected

I've started building an app that uses NFC to communicate towards a device.

The initial communication is being triggered as intended, the last step of authentication is sent the connection seems to drop with the message: -[_NFCardSession validateReceivedAPDU:]:236 Invalid ISO7816 APDU detected, (null)

The same response has been validated on an Android device and the process works fine there, but .readerDeselected is triggered instead of .received with cardAPDU.

Any way to see which part of the validation that fails?

Best regards

We will need some diagnostic information about your app and code to be able to diagnose this issue.

For that purpose, please open a support request at https://developer.apple.com/contact/request/code-level-support/ and reference this forum thread in the "Did someone from Apple ask you to submit ..." section


Argun Tekant /  DTS Engineer / Core Technologies

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
-[_NFCardSession validateReceivedAPDU:]:236 Invalid ISO7816 APDU detected
 
 
Q