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到com.apple.developer.nfc.readersession.iso7816.select-identifiersInfo.plist条目中的解决方案,现在看起来像这样:
<key>com.apple.developer.nfc.readersession.iso7816.select-identifiers</key>
<array>
    <string>A0000002471001</string>
    <string>00000000000000</string>
</array>
| 归档时间: | 
 | 
| 查看次数: | 1111 次 | 
| 最近记录: |