okadan / nfc-manager

A Flutter app for accessing the NFC features on Android and iOS.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Handling 'Tag was lost' error

ishwaryamamidi opened this issue · comments

Scenario: When the mobile app is trying to scan the nfcV tag using 'OnDiscovered' method, and due to some interruptions (like may be user suddenly removed the tag in between before complete scan), an error occurs called
Exception has occurred. PlatformException (PlatformException(io_exception, Tag was lost., null)).

I tried to handle this with 'onError' method, but still error doesn't get caught.
Any suggestions how to handle this?

@ishwaryamamidi
onError catches errors related to the session on iOS.
See: https://pub.dev/documentation/nfc_manager/latest/nfc_manager/NfcManager/startSession.html

(iOS only) onError is called when the session is stopped for some reason after the session has started.

To catch an error related to tags:

NfcManager.instance.startSession(
  onDiscovered: (tag) async {
    final nfcv = NfcV.from(tag);
    try {
      await nfcv.transceive(...);
    } catch (e) {
      print(e); // => "Tag was lost" exception.
    }
  },
);

When I try to scan the tag using IOS, I get the below error:

[NFCTagReaderSession beginSessionWithConfig:]:315 error:Error Domain=NFCError Code=202 "Session invalidated unexpectedly" UserInfo={NSLocalizedDescription=Session invalidated unexpectedly}, errorCode: 0xca

When I use the below method:

NfcManager.instance.startSession(
onDiscovered: (tag) async {
print('tag $tag');
});

Any idea what could be the reason for this error?

@okadan Can you help me.
What data are to be sent to nfcv.transceive(......);
to unlock tag then write on tag.