Hi,
I'm developing an app for communicate through NFC.
I've:
- setted "NFC Tag Reading" capability for app on Apple project page.
- use iPhone 7 and iOS 11.4.1 (the last iOS version)
- added in entitlement file
<key>com.apple.developer.nfc.readersession.formats</key>
<array>
<string>NDEF</string>
</array>
- added in info.plist file
<key>NFCReaderUsageDescription</key>
<string>NFC Read</string>
- write a simple ViewController to manage NFC Communication
var nfcSession: NFCNDEFReaderSession!
func startScanning(){
nfcSession = NFCNDEFReaderSession(delegate: self, queue: DispatchQueue.main, invalidateAfterFirstRead: false)
nfcSession.alertMessage = "You can hold you NFC-tag to the back-top of your iPhone"
nfcSession.begin()
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
startScanning()
}
extension NfcReaderViewController : NFCNDEFReaderSessionDelegate {func readerSession(_ session: NFCNDEFReaderSession, didInvalidateWithError error: Error) {
print("Error reading NFC: \(error.localizedDescription)")
//session.invalidate()
//self.startScanning()
}
func readerSession(_ session: NFCNDEFReaderSession, didDetectNDEFs messages: [NFCNDEFMessage]) {
//Never called
}
}
However, when the phone is near to NFC tag that send NDEF messages, I obtain always this error:
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
Moreover I try to scan NFC tags through more app downloaded from the store, and also in them I obtain a similar error.
There is a reason?
Apple documentation is poor and doesn't explain nothing on errors received.
Thank you!