Posts

Post not yet marked as solved
5 Replies
4.4k Views
We send APDU command to ISO-7816 tag and receive the resposne, but some error occurred.Exceeding 1694 bytes will failureWe send the APDU command. The phone successfully get response from PN7150 when the length of response is under 1694 bytes, but we get an error when the length of response is greater than or equal to 1694 bytes.The exception as follows : Error Domain=NFCError Code=100 "Tag connection lost"Android can workWe use Android to test same function, it can be executed successfully.I think the APDU command on iOS has the response limit or other issue.It is the result of ours test on iOS :send 100 bytes, response 1529 bytes : occasionally success.send 100 bytes, response 1200 bytes : success.send 0 byte, response 1694 bytes : error.send 0 byte, response 1693 bytes : success.CodeThe following is the part of the send and receive APDU.func tagReaderSession(_ session: NFCTagReaderSession, didDetect tags: [NFCTag]) { var tag: NFCTag? = nil for nfcTag in tags { if case .iso7816(_) = nfcTag { session.alertMessage = "Detect an iso7816 tag." tag = nfcTag } } if tag == nil { session.invalidate(errorMessage: "No valid tag found.") return } session.connect(to: tag!) { (error: Error?) in if error != nil { session.invalidate(errorMessage: "Connection error. Please try again.") return } guard case let .iso7816(iso7816Tag) = tag else { return } let CLA: UInt8 = 0x00 let INS: UInt8 = 0xB0 let p1: UInt8 = 0x00 let p2:UInt8 = 0x04 let data : Data = self.stringToHex(self.message) // sent data let Le:Int = 1500 // extends APDU let apduCommand = NFCISO7816APDU(instructionClass: CLA,instructionCode: INS,p1Parameter: p1,p2Parameter: p2,data: data,expectedResponseLength: Le) iso7816Tag.sendCommand(apdu: apduCommand) { (response: Data, sw1:UInt8, sw2:UInt8, error: Error?) in // if response > 1694 bytes , error occurred if error != nil { self.readerSession?.invalidate(errorMessage: "Send command tag error. Please try again.") return } print(String(data:response,encoding: .ascii)!) self.readerSession?.alertMessage = "Send Command Success!" self.readerSession?.invalidate() } } }Thank you.
Posted
by zxa011023.
Last updated
.