1

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()
    }
Firda Sahidi
  • 1,227
  • 1
  • 11
  • 22
  • Is it possible to communicate with a credit (payment) card using CoreNFC? Apple doc says that "Core NFC doesn't support payment-related Application IDs." If you found the way how to bypass this restriction, please tell us your "know how"... – Олег Сидоров Jun 04 '22 at 09:03
  • Yes it is possible. But you have to know more about the card they're using and finding the correct APDU method to read it. – Firda Sahidi Jun 06 '22 at 10:13
  • Thanks! I am aware about ISO7816, ISO14443, EMV. But how do you communicate with the card? Core NFC must detect NFC device first, then returns you descriptor of the tag, and only after that I can send APDU to the "tag". As I know, even NFC tools application does not "see" the card on iOS. Thus, I was able to send "row" APDU messages to the card only on android. So, how to start communication with the card? If I do so, I am able to make manually sequence of commands like PSE, SELECT, GPO, and so on… – Олег Сидоров Jun 07 '22 at 11:12

0 Answers0