You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何获取ISO-15693 NFC设备的总内存字节数?

获取ISO-15693 NFC设备总内存字节数(iOS CoreNFC实现)

CoreNFC的NFCISO15693Tag协议没有直接提供内存总量的属性,但你可以通过发送ISO-15693标准的「Get System Information」命令来获取——第三方App也是用这个方法实现的。

实现步骤:

  1. 配置NFC权限

    • 在Info.plist中添加NFCReaderUsageDescription字段,填写权限说明文本
    • 在Xcode项目的「Signing & Capabilities」中开启「Near Field Communication Tag Reading」能力
    • 确保测试设备为iPhone 7及以上机型(支持NFC功能)
  2. 发送命令并解析响应
    连接到ISO-15693标签后,使用sendCommand(_:completionHandler:)发送命令码为0x0B的Get System Information命令,再根据标签厂商的规范解析返回数据。

示例代码:

import CoreNFC

class NFCReaderDelegate: NSObject, NFCNDEFReaderSessionDelegate {
    func readerSession(_ session: NFCNDEFReaderSession, didDetect tags: [NFCNDEFTag]) {
        guard let tag = tags.first else { return }
        session.connect(to: tag) { [weak self] error in
            guard error == nil, let isoTag = tag as? NFCISO15693Tag else {
                session.invalidate(errorMessage: "无法连接ISO-15693标签")
                return
            }
            // 发送Get System Information命令
            let command = Data([0x0B])
            isoTag.sendCommand(command) { response, error in
                defer { session.invalidate() }
                if let error = error {
                    session.alertMessage = "命令失败: \(error.localizedDescription)"
                    return
                }
                guard let respData = response, respData.count >= 3 else {
                    session.alertMessage = "无法解析内存信息"
                    return
                }
                // 示例解析:不同标签需参考厂商 datasheet 调整
                let blockCount = Int(respData[1])
                let bytesPerBlock = Int(respData[2])
                let totalBytes = blockCount * bytesPerBlock
                session.alertMessage = "总内存: \(totalBytes) 字节"
                print("总内存字节数: \(totalBytes)")
            }
        }
    }
    
    func readerSession(_ session: NFCNDEFReaderSession, didInvalidateWithError error: Error) {
        // 处理会话失效逻辑
    }
}

// 启动NFC会话
let nfcSession = NFCNDEFReaderSession(delegate: NFCReaderDelegate(), queue: nil, invalidateAfterFirstRead: true)
nfcSession.begin()

注意事项:

  • 不同厂商的ISO-15693标签返回的响应结构可能不同,必须参考对应标签的技术文档调整解析逻辑。例如部分标签会用双字节表示块数,或直接返回总容量的编码值。
  • 若标签不支持Get System Information命令,可能需要尝试发送厂商自定义命令来获取内存信息。

内容的提问来源于stack exchange,提问作者Giorgio

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.02 13:35:01