Post

Replies

Boosts

Views

Activity

Reply to CoreNFC NFCISO7816APDU sendCommand Tag connection lost
I am working on scanning a MiFare tag and reading the EEPROM (NDEF) and SRAM part by sending mifareTag.sendMiFareCommands. This works very well in a test app where I just feed static commands from an array to the tag, but gives a lot of problems (Tag connection lost or responseBlocks not giving back results or ACK's), when giving exactly the same commands from an app where all command parameters are calculated. What (probably...) solved it for me was defining mij own serial queue:let tagScanQueue = DispatchQueue(label: "xxxxxxxx.tagScanQueue", qos: .userInitiated)tagReaderSession = NFCTagReaderSession(pollingOption: .iso14443, delegate: self, queue: tagScanQueue)and wrapping every function calling my mifareTag.sendMiFareCommands function in tagScanQueue.asyncAfter: private func sendCommandXxxxxx(to mifareTag: NFCMiFareTag) { tagScanQueue.async { self.sendCommand(xxxxxx, to: mifareTag) { result in ... } } } private func sendCommand(_ mfCommand: MFCommandContent, to mifareTag: NFCMiFareTag, returnResult: @escaping (Data) -> Void) { tagScanQueue.asyncAfter(deadline: .now() + .milliseconds(mfCommand.delay)) { mifareTag.sendMiFareCommand(commandPacket: mfCommand.command) { responseBlock, error in if let error = error { self.invalidateScan(.tagInvalid(messageCode: 123)) // MiFare command gives an error return } guard responseBlock.count != 1 || responseBlock == Data([0x0A]) else { self.invalidateScan(.tagInvalid(messageCode: 456)) // MiFare command gives an invalid response return } returnResult(responseBlock) } } }Maybe this helps you?
Nov ’19