I'm trying to build an iOS app for reading money/transportation card (eg. credit card) information. My apps already detect it. However, I still can't get the data inside the byte I retrieve.
Here's my APDU command code:
if case let .iso7816(tag) = nfcTag {
let apdu = NFCISO7816APDU(instructionClass: 13, instructionCode: 0xB2, p1Parameter: 0, p2Parameter: 0, data: ReaderType.cardInfo.rawValue.hexStringToData(), expectedResponseLength: 32)
self.tagSession?.alertMessage = "Select Command Success!"
tag.sendCommand(apdu: apdu) { (data:Data, sw1:UInt8, sw2:UInt8, error:Error?) in
guard error == nil else {
print("Error send command: \(error!)")
session.invalidate(errorMessage: "Error send command: \(error!)")
return
}
self.processingData(data: data, sTag: tag, session: session)
}
}
}
}
Here's my data processing code:
func processingData(data: Data, sTag: NFCISO7816Tag, session: NFCReaderSession) {
print(String(data:data,encoding: .utf8) ?? "")
let tagUIDData = sTag.identifier
var byteData: [UInt8] = []
tagUIDData.withUnsafeBytes { byteData.append(contentsOf: $0) }
var uidString = ""
for byte in byteData {
let decimalNumber = String(byte, radix: 16)
if (Int(decimalNumber) ?? 0) < 10 {
uidString.append("0\(decimalNumber)")
} else {
uidString.append(decimalNumber)
}
}
print("\n\(byteData) converted to Tag UID: \(uidString)")
let value: String = getBalanceTagConverter(byteData.hexa)
print("\ncardUID : \(value)")
self.tagSession?.alertMessage = "Your UID is \(byteData.hexa)"
self.tagSession?.invalidate()
}