【问题标题】:How to format an empty (NDEFFormatable) NFC Tag in iOS如何在 iOS 中格式化一个空的(NDEFFormatable)NFC 标签
【发布时间】:2019-12-09 10:58:31
【问题描述】:

我目前正在使用一些 NFC 标签和 iOS 13。

一个问题是,我的一些 NFC 标签是作为NDEFFormatable 交付的。我知道我必须先格式化标签才能使用 NDEF。我可以使用第 3 方 Android 应用程序来做到这一点。但是我怎么能用我自己的 iOS 应用程序做到这一点呢? 目前该标签被识别为“ISO15693”标签,queryNDEFStatus 方法的结果为.notSupported

我也尝试向该 NFC 标签写入 empoty 消息,但 iOS 响应错误“NDEF 标签是只读的”

据我所知,您喜欢这里的一些代码是重要的部分:

session = NFCTagReaderSession(pollingOption: [.iso14443, .iso15693], delegate: self)
    session?.alertMessage = "Bitte halten Sie das Gerät an den zu scannenden NFC Tag"
    session?.begin()

...

func tagReaderSession(_ session: NFCTagReaderSession, didDetect tags: [NFCTag]) {

    if tags.count > 1 {
        // Restart polling in 500ms
        let retryInterval = DispatchTimeInterval.milliseconds(500)
        session.alertMessage = "Mehr als 1 NFC Tag gefunden. Bitte scannen Sie jeden Tag einzeln."
        DispatchQueue.global().asyncAfter(deadline: .now() + retryInterval, execute: {
            session.restartPolling()
        })
        return
    }

    let tag = tags.first!

    // Connect to the found tag and perform NDEF message reading
    session.connect(to: tag) { (error: Error?) in

        if nil != error {
            session.invalidate(errorMessage: "NFC Tag konnte nicht gelesen werden")
            return
        }

        if case let NFCTag.iso15693(iso15693Tag) = tag{

            iso15693Tag.queryNDEFStatus(completionHandler: { (ndefStatus: NFCNDEFStatus, capacity: Int, error: Error?) in

                guard error == nil else {
                    session.invalidate(errorMessage: "Status des Tags konnte nicht gelesen werden")
                    return
                }

                switch ndefStatus {
                case .notSupported:

                    //NDFEFFormatable tag is handled here !!!!

                    session.alertMessage = "Der Tag unterstützt das NFC Data Exchange Format (NDEF) nicht!"
                    session.invalidate()
                case .readOnly:
                    //read tag
                case .readWrite:
                     //read or write tag
                @unknown default:
                    session.alertMessage = "Unbekannter Status"
                    session.invalidate()
                }
            })
        } else if case let NFCTag.miFare(miFareTag) = tag { //check if we have a MiFare Tag
            //other type of tags

        } else {
            session.invalidate(errorMessage: "Dieser Tag wird aktuell leider nicht unterstützt")
            return
        }
    }
}

【问题讨论】:

  • 那成功了吗?

标签: ios nfc core-nfc


【解决方案1】:

一些消息来源说 iOS 只能使用已经格式化的卡片

https://help.gototags.com/article/nfc-tag-encoding-iphone/

但是您也许可以使用低级命令编写正确的块来自己格式化卡。

你没有指定卡的类型,所以假设它是类型 2 http://apps4android.org/nfc-specifications/NFCForum-TS-Type-2-Tag_1.1.pdf(如果不是其他规格在 http://apps4android.org/nfc-specifications/

但可能更像是我无法访问规格的 Type 5 Card,但 Type 5 与 Type 2 可以做类似的事情(您可以使用各种 Android 应用程序,如 NXP 的 Taginfo 应用程序来比较格式化的NDEF V 型标签和非格式化标签,看看它是否也是 V 型卡上的块 3 和 4)

但对于类型 2

第 6.4.1 节展示了它如何检测到它是 NDEF 格式的卡。

对于类型 2 卡块 03 必须有 4 字节的 NDEF 能力容器,很多卡在工厂都有这个预设,如果没有你需要将 4 字节的能力容器写入块 03。

容器格式在规范中,但以下是摘要:-

字节 0 = E1h 表示标签内部存在 NDEF 数据

字节 1 = 10h 表示支持映射文档(即本规范的版本)的 1.0 版(主要编号 1h,次要编号 0h)。 - 1.0 版是我认为的最新版本。

字节 2 = 数据区的大小,因此是卡特定的值,但该值是数据区大小除以 8 并以十六进制表示。例如128字节数据存储指示值等于10h

字节 3 = 关于安全性,值 0h 表示授予的写访问权限没有任何安全性


然后你需要用一个空白的TLV消息格式化卡到block 4来格式化卡。

块 4 中的空白 TLV 消息是

字节 0 = 03h

字节 1 = 00h

字节 2 = FEh

这基本上等同于开始 NDEF 消息,消息长度为零,结束 NDEF 消息。


我没有在 iOS 上做过任何这些,但似乎 iOS 确实提供了 ISO15693 标签的低级读写访问

https://developer.apple.com/documentation/corenfc/nfciso15693tag/3043817-writesingleblock

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-10-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-09
    • 2015-02-08
    • 1970-01-01
    相关资源
    最近更新 更多