iOS CoreNFC – 类“NFTechnologyEvent”未加载或不存在

尝试使用iPhone 7 Plus读取NFC标签时出现此错误

2017-12-13 14:03:01.522137-0300 nfc [279:9534] [general]与名为com.apple.nfcd.service.corenfc的服务的连接:在解码收到的消息,丢弃传入消息时捕获exception。

exception:解码参数0时的exception(调用的#2):

例外:decodeObjectForKey:类“NFTechnologyEvent”未加载或不存在

我有适当的权利( Near Field Communication Tag Reading )和Privacy - NFC Scan Usage Description设置。

要重现它,只需启动一个新的单个视图项目,并用以下代码替换默认的ViewController

 import UIKit import CoreNFC class ViewController: UIViewController, NFCNDEFReaderSessionDelegate { // Reference the NFC session private var nfcSession: NFCNDEFReaderSession! override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. self.startScanning() } func startScanning() { // Create the NFC Reader Session when the app starts self.nfcSession = NFCNDEFReaderSession(delegate: self, queue: nil, invalidateAfterFirstRead: false) // A custom description that helps users understand how they can use NFC reader mode in your app. self.nfcSession?.alertMessage = "Macri Gato" self.nfcSession?.begin() } // Called when the reader-session expired, you invalidated the dialog or accessed an invalidated session public func readerSession(_ session: NFCNDEFReaderSession, didInvalidateWithError error: Error) { print("NFC-Session invalidated: \(error.localizedDescription)") print("==========================") self.startScanning() } // Called when a new set of NDEF messages is found public func readerSession(_ session: NFCNDEFReaderSession, didDetectNDEFs messages: [NFCNDEFMessage]) { print("New NFC Messages (\(messages.count)) detected:") print(messages) } }