iOS CoreNFC - class “NFTechnologyEvent” not loaded

2019-07-04 04:51发布

问题:

I'm getting this error when trying to read a NFC tag using an iPhone 7 Plus

2017-12-13 14:03:01.522137-0300 nfc[279:9534] [general] connection to service named com.apple.nfcd.service.corenfc: Exception caught during decoding of received message, dropping incoming message.

Exception: Exception while decoding argument 0 (#2 of invocation):

Exception: decodeObjectForKey: class "NFTechnologyEvent" not loaded or does not exist

I have the proper entitlement (Near Field Communication Tag Reading) and Privacy - NFC Scan Usage Description setted.

To reproduce it just start a new single view project and replace the default ViewController with this:

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)
    }
}