“标签连接丢失";在iOS 13上读取Mifare Ultralight NFC标签时发生错误 [英] "Tag connection lost" error when reading a Mifare Ultralight NFC tag on iOS 13

查看:433
本文介绍了“标签连接丢失";在iOS 13上读取Mifare Ultralight NFC标签时发生错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试阅读Mifare Ultralight标签的页面(更具体地说,是 发现并连接到NFCMifareTag.sendMifareCommand 方法之后.问题是我尝试发送的所有命令都导致标记连接丢失"错误,这很奇怪,因为我刚刚成功连接到它.

I'm trying to read a page of a Mifare Ultralight tag (more specifically EnOcean PTM 215B) using NFCMifareTag.sendMifareCommand method after it has been discovered and connected onto. The problem is that all commands I've tried to send cause a "Tag connection lost" error which is quite odd as I've just successfully connected to it.

(简化的)代码如下:

// 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 命令的示例.

I'd appreciate any pointers and/or ideas on what could be the reason for this behavior. As mentioned, I've tried various different data packets but all work exactly the same. I've also tried multiple different phones to eliminate hardware problems. The support was just added in iOS 13 and as such I couldn't find any examples online that would use the sendMifareUltralight command.

推荐答案

根据API(CoreNFC/NFCMiFareTag),将自动计算并插入CRC.因此,在您的情况下,您只需要发送 [0x30,0x04] 来读取第4到7页,读取命令 0x30 将读取4页,您将获得16个字节.

According to the API (CoreNFC/NFCMiFareTag) the CRC will be calculated and inserted automatically. So in your case you only need to send [0x30, 0x04] to read page 4 to 7, the read command 0x30 will read 4 pages you will get 16 bytes.

 /**
 * @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)

这篇关于“标签连接丢失";在iOS 13上读取Mifare Ultralight NFC标签时发生错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆