Skip to content

iOS: treat empty NDEF tags as empty result instead of NFCReaderError.Code.ndefReaderSessionErrorZeroLengthMessage #265

Description

@Ajinkya-GobetterX

Package

nfc_manager 4.1.1

Platform

iOS

Summary

Reading an empty / erased NDEF tag on iOS returns:

NFCReaderError.Code.ndefReaderSessionErrorZeroLengthMessage

For apps that support blank or erased tags, this behavior forces consumers to treat an empty tag as a hard failure. In practice, this is more useful as a successful read with no NDEF message.

Actual behavior

Calling readNDEF on an empty tag surfaces an error:

  • NFCReaderError.Code.ndefReaderSessionErrorZeroLengthMessage

Expected behavior

Return a successful result with nil / empty NDEF content instead of failing the read.

Why this matters

Apps that:

  • erase NFC tags
  • initialize blank tags
  • inspect tags before writing

need to handle empty NDEF tags as a normal state.

Right now, the only workaround is patching the plugin locally.

Proposed fix

In ios/Classes/NfcManagerPlugin.swift, handle ndefReaderSessionErrorZeroLengthMessage as an empty result:

if let readerError = error as? NFCReaderError,
   readerError.code == .ndefReaderSessionErrorZeroLengthMessage {
  completionHandler(pigeon, nil)
  return
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions