使用CoreNFC检测ISO/IEC 14443(Mifare超轻或经典)NFC卡 [英] Detect ISO/IEC 14443 (Mifare Ultralight or Classic) NFC Cards with CoreNFC

查看:488
本文介绍了使用CoreNFC检测ISO/IEC 14443(Mifare超轻或经典)NFC卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我在WWDC上,能够检测到Apple Labs提供的带有以下代码的NFC卡:

So I was at the WWDC and was able to detect NFC Cards provided by Apple Labs with the following code:

nfcSession = NFCNDEFReaderSession(delegate: self, queue: nil, invalidateAfterFirstRead: false)
nfcSession.begin()

和委托方法:

func readerSession(_ session: NFCNDEFReaderSession, didInvalidateWithError error: Error) {
    DispatchQueue.main.async {
        print("Error:" + error.localizedDescription)
    }
}

func readerSession(_ session: NFCNDEFReaderSession, didDetectNDEFs messages: [NFCNDEFMessage]) {
    print("Did detect NDEFs.")
    for message in messages {
        for record in message.records {
            print(record.identifier)
            print(record.payload)
            print(record.type)
            print(record.typeNameFormat)
        }
    }
}

但是,我想在ISO/IEC 14443协议下检测Mifare Ultralight(或经典)卡.

How ever, I want to detect a Mifare Ultralight (Or classic) card under the ISO/IEC 14443 protocol.

每当我获得扫描视图"时,什么都不会发生.错误回调或成功块也不会被调用.有没有办法读取这张卡?

Whenever I get the Scan View, nothing happens. Nor the error callback or the success block get called. Is there a way to read this cards?

非常感谢!

推荐答案

MIFARE Classic 1k或4k芯片早于ISO/IEC 14443标准.在WWDC CoreNFC演示中,没有明确提到CoreIFC支持MIFARE Classic.

The MIFARE Classic 1k or 4k chips predate the ISO/IEC 14443 standard. In the WWDC CoreNFC presentation, MIFARE Classic is not explicitly mentioned to be supported by CoreNFC.

支持MIFARE Ultralight或任何其他2型标签(例如NTAG 203).我认为MIFARE Classic的后继产品将是Type 4(DESFire).

MIFARE Ultralight is supported, or any other Type 2 Tag (e.g. NTAG 203). The successor of MIFARE Classic would be Type 4 (DESFire), I think.

话虽如此,我可以成功读取MIFARE Classic 1k标签,如果所有16个扇区密钥A& B均保留出厂默认设置,并且该标签包含有效的NDEF消息.即使更改了一个键,读取器也会由于readerSessionInvalidationErrorUserCanceled而中止.

Having said this, I could successfully read a MIFARE Classic 1k Tag, if all of the 16 sector keys A&B are left at the factory default, and if the tag contains a valid NDEF message. If even one key is changed, the reader aborts with readerSessionInvalidationErrorUserCanceled.

根据我的经验,Beta 2在读取标签时要可靠得多.在我的手机上,第一次读取始终会失败,因此我必须停止并重新启动读取器会话.从那时起,它运行良好.在Beta 1中,我常常不得不先重新启动手机,甚至然后重新启动手机多次才能取消/重试.

Beta 2 is a lot more reliable when reading tags, in my experience. On my phone, the very first read always fails, and I have to stop and restart the reader session. From then on, it works fine. With beta 1, I often had to reboot the phone first, and even then hat to cancel/retry many times.

NXP-MIFARE标签的供应商-发布了一个规范,该规范说明了如何在MIFARE经典标签内存储NDEF标签.我的测试表明,可以使用CoreNFC库读取此类标签而不会出现问题. Adafruit已为Arduino发布了一个库,该库可以根据此规范重新格式化MIFARE经典标签.

NXP - the vendor of MIFARE Tags - has published a specification that explains how to store NDEF tags inside of a MIFARE classic tag. My tests show that such tags can be read with the CoreNFC library without problems. Adafruit has published a library for Arduino that allows to reformat a MIFARE classic tag according to this specification.

之前,我使用了另一个NDEF Arduino库,该库使用了不同的方法,与规范不符.有时,无论如何都可以读取标签,但无法可靠读取.

Earlier I used another NDEF Arduino library that used a different approach, not in-line with the specification. Sometimes the tags could be read anyway, but not reliably.

结论:确保100%确保使用的标签是根据已发布的规范进行格式化的.如果您无法读取在抽屉中找到的标签,则可能不是CoreNFC库的问题.

In conclusion: Make 100% sure that you use a tag that is formatted according to the published specifications. If you can't read a tag that you found in your drawer, it's probably not the fault of the CoreNFC library.

这篇关于使用CoreNFC检测ISO/IEC 14443(Mifare超轻或经典)NFC卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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