Ошибка «Потеря соединения с тегом» при чтении метки Mifare Ultralight NF C на iOS 13 - PullRequest
0 голосов
/ 26 февраля 2020

Я пытаюсь прочитать страницу тега Mifare Ultralight (точнее, EnOcean PTM 215B ), используя метод NFCMifareTag.sendMifareCommand после его обнаружения и подключения к нему. Проблема в том, что все команды, которые я пытался отправить, вызывают ошибку «Потеря соединения с тегом», что довольно странно, поскольку я только что успешно к ней подключился.

(упрощенный) код выглядит следующим образом:

// tag has been determined to be of type NFCMifareTag earlier
session.connect(to: tag) { (error: Error?) in
  if (error != nil) {
    return
  }

  print("Connected to the tag")

  let data: [UInt8] = [0x30, 0x04, 0xEE, 0x26] // READ page 4 + CRC
  let dataPacket = Data(bytes: data, count: data.count)

  tag.sendMifareCommand(
    commandPacket: dataPacket,
    completionHandler: { (response: Data?, error: Error?) in
      if nil != error {
        return // <-- "Tag connection lost" error
      }
      // Handle the data as the operation was successful
    }
  )
}

Буду признателен за любые указания и / или идеи о том, что может быть причиной такого поведения. Как уже упоминалось, я пробовал различные пакеты данных, но все они работают одинаково. Я также пробовал несколько разных телефонов, чтобы устранить проблемы с оборудованием. Поддержка была только что добавлена ​​в iOS 13, и поэтому я не смог найти в Интернете ни одного примера, в котором бы использовалась команда sendMifareUltralight.

1 Ответ

1 голос
/ 29 февраля 2020

Согласно API (CoreNFC / NFCMiFareTag) CR C будет рассчитан и вставлен автоматически. Таким образом, в вашем случае вам нужно только отправить [0x30, 0x04] для чтения страниц 4-7, команда чтения 0x30 прочитает 4 страницы, вы получите 16 байтов.

 /**
 * @method sendMiFareCommand:completionHandler:
 *
 * @param command           The complete MiFare command.  CRC bytes are calculated and inserted automatically to the provided packet data frame.
 * @param completionHandler Completion handler called when the operation is completed.  error is nil if operation succeeds. A @link NFCErrorDomain @link/ error
 *                          is returned when there is a communication issue with the tag. Successfully read data blocks will be returned from the NSData object.
 *
 * @discussion              Send native MIFARE command to a tag.  Support MIFARE UltraLight, Plus, and DESFire products.
 *                          Crypto1 protocol is not supported.  Command chainning is handled internally by the method and the full response composed of the
 *                          individual fragment is returned in the completion handler.
 */
@available(iOS 13.0, *)
func sendMiFareCommand(commandPacket command: Data, completionHandler: @escaping (Data, Error?) -> Void)
...