TKSmartCard transmit command on iOS fails after 600 ms.

Hello everyone.

iOS 16 added ability to connect usb devices. TKSmartCard works well with just a fast command, but if it takes more than 600ms TKSmartCard.transmit fails with communication error -2. Is there a workaround or am I use it wrong?

Usage looks like that:

import CryptoTokenKit


func foo() {
    guard let manager = TKSmartCardSlotManager.default else {
        return
    }

    let names = manager.slotNames

    let smartCards = names.compactMap { manager.slotNamed($0) }
        .filter { $0.state == .validCard }
        .compactMap { $0.makeSmartCard() }

    guard let card = smartCards.first else {
        return
    }

    let apdu = Data([/*command that lasts longer than 600 ms*/])

    Task {
        do {
            guard try await card.beginSession() else {
                print("beginSession failed")
                return
            }

            let res = try await card.transmit(apdu)
            print(res.map { String(format: "0x%02X", $0) }.joined(separator: ", "))
        } catch {
            print(error)
        }
    }
}
Post not yet marked as solved Up vote post of kamenov Down vote post of kamenov
1.4k views
  • I reported a bug: FB11795102 (TKSmartCard transmit command on iOS fails after 600 ms)

Add a Comment

Replies

Hi kamenov, which reader have you connected to the device to access the smart card ? I'm using Feitian iR301-U reader plugging to the lightning port but it doesn't seems to work.