Hi everyone,
I'm working on an NFC-related app using CoreNFC with APDU commands to read and write tags. I’ve encountered an issue when trying to handle the scenario where the user cancels the NFC session.
Here’s what’s happening:
When a user cancels the NFC session manually (e.g., by tapping "Cancel"), I see an error log indicating tagReaderSession|userCancelled. However, when I explicitly call session.invalidate(errorMessage: "No NFC tag found") in my code to handle a scenario where no tag is detected, the session still shows the error as userCancelled instead of my custom error message. This behavior is confusing both in terms of debugging and for providing feedback to users, as I expect my custom message to appear instead of the generic "user cancelled" message.
func tagReaderSessionDidBecomeActive(_ session: NFCTagReaderSession) {
// Session becomes active
}
func tagReaderSession(_ session: NFCTagReaderSession, didDetect tags: [NFCTag]) {
// Handle tag detection logic
}
func tagReaderSession(_ session: NFCTagReaderSession, didInvalidateWithError error: Error) {
print("Session invalidated with error: \(error.localizedDescription)")
}
func handleNoTagDetected(session: NFCTagReaderSession) {
session.invalidate(errorMessage: "No NFC tag found")
}
I call handleNoTagDetected(session:) explicitly when no tag is detected, expecting the custom error message to show. However, the system still shows the cancellation error.
Has anyone else experienced this behavior? Is this the intended behavior for CoreNFC, or am I missing something in my implementation?
Any guidance would be appreciated.
Thanks in advance!