send(ins:p1:p2:data:le:reply:)
Asynchronously transmits an APDU command to the card, returning the response in a completion handler.
Declaration
func send(ins: UInt8, p1: UInt8, p2: UInt8, data: Data? = nil, le: Int? = nil, reply: @escaping (Data?, UInt16, (any Error)?) -> Void)Parameters
- ins:
The instruction code.
- p1:
The first parameter.
- p2:
The second parameter.
- data:
The data field, or
nilif no input data field is present—for example, acase1orcase2APDU.The length of the data serves as
Lcfield of the APDU. - le:
The expected number of bytes to be returned, or
nilif no output data are expected—for example, acase1orcase3APDU. Pass0to accept as many bytes as the card provides. - reply:
A closure to call when the response is returned from the card.
- replyData
The returned data without the first two bytes (
SW1SW2), ornilif an error occurred.- sw
The result code as represented by the first two bytes (
SW1SW2) of the returned data.- error
If a communication error occurred or the result code is anything other than
0x9000, contains details about the error.
Discussion
This call handles all ISO7816-4 APDU cases, translating to proper the sequences according to the protocol. It consults the useExtendedLength and useCommandChaining properties and uses these modes whenever appropriate for sending the APDU request.