swift - 使用iOS13无法读取电子护照的NFC芯片

标签 swift nfc ios13

import UIKit
import CoreNFC

class ViewController: UIViewController, NFCTagReaderSessionDelegate {

    var nfcTagReaderSession: NFCTagReaderSession?

    func tagReaderSessionDidBecomeActive(_ session: NFCTagReaderSession) {
        print("Tag reader did become active")
        print("isReady: \(nfcTagReaderSession?.isReady)")
    }

    func tagReaderSession(_ session: NFCTagReaderSession, didInvalidateWithError error: Error) {
        print("\(error)")
    }

    func tagReaderSession(_ session: NFCTagReaderSession, didDetect tags: [NFCTag]) {
        // this part is never called!
        print("got a Tag!")
        print("\(tags)")
    }

    @IBAction func clickedNFC(_ sender: Any) {
        nfcTagReaderSession = NFCTagReaderSession(pollingOption: [.iso14443], delegate: self)

        nfcTagReaderSession?.alertMessage = "Place the device on the innercover of the passport"
        nfcTagReaderSession?.begin()
        print("isReady: \(nfcTagReaderSession?.isReady)")

    }

}

我的权利文件中也有

<key>com.apple.developer.nfc.readersession.formats</key>
<array>
    <string>NDEF</string>
    <string>TAG</string>
</array>

在我的 Info.plist 中

<key>NFCReaderUsageDescription</key>
<string>Read the NFC chip of ePassports</string>
<key>com.apple.developer.nfc.readersession.iso7816.select-identifiers</key>
<array>
    <string>A0000002471001</string>
</array>

我的问题是 tagReaderSession(_ session: NFCTagReaderSession, didDetect tags: [NFCTag]) 从未被调用。我错过了什么?

最佳答案

我找到了我将 00000000000000 添加到 Info.plist 中的 com.apple.developer.nfc.readersession.iso7816.select-identifiers 条目的解决方案 现在看起来像这样:

<key>com.apple.developer.nfc.readersession.iso7816.select-identifiers</key>
<array>
    <string>A0000002471001</string>
    <string>00000000000000</string>
</array>

关于swift - 使用iOS13无法读取电子护照的NFC芯片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56515747/

相关文章:

UIKit 的 textColor 的 iOS13 白色问题

ios - 在 Swift 3 中,如何在转换到另一个 SKView 时传递变量?

ios - iOS 13 上未调用supportedInterfaceOrientations

objective-c - iOS 13 上 TableView 错误的 Diffable 数据源 : Inconsistent associations for moves

ios - 如何编写面向协议(protocol)的部分

android - 使用 NFC 消息一次可以发送多少个字符?

Android:NFC 标签技术 -> 是否应该检查它们,如果是,如何检查?

android - 如何编写将离线启动浏览器并显示 html 的 NFC 标签?

swift - 'scanHexInt32' 在 iOS 13.0 中被弃用

ios - 为什么约束更改或动画不需要调用setNeedsUpdateConstraints?