revtel / react-native-nfc-manager

React Native NFC module for Android & iOS
MIT License
1.39k stars 317 forks source link

How to scan multiple NFC chips at once? #706

Closed sarisssa closed 4 months ago

sarisssa commented 7 months ago

I want to be able to scan multiple chips at once without the iOS Scan Modal Screen disappearing if the user presses a Keep Scanning toggle in the front end.

My approach barely works but the main issue I'm getting is that I keep getting Oops! [Error: Duplicated registration] and the iOS Scan Modal Screen keeps on appearing. I assume it's because I don't cancel the NFC registration properly?

Alternatively, should I amend the below and use the setEventListener and registerTagEvent API?

async function readNdef() {
    while (isKeepScanning) {
      try {
        console.log("Batch Register");
        await scanChip();
        console.log("FINISH SCAN");
        await NfcManager.cancelTechnologyRequest();
      } catch (ex) {
        if (!isKeepScanning) {
          console.log(ex);
          setIsAuth(false);
        }
      } finally {
        console.log("FINALLY");
        await NfcManager.cancelTechnologyRequest();
      }
    }
    scanChip();
  }

  const scanChip = async () => {
    try {
      await executeNfcCommand(NfcManager, {
        name: "authenticateEv2First",
        key: 0,
      });

      setIsAuth(true);
      await NfcManager.cancelTechnologyRequest();
    } catch (ex) {
      // console.log("Oops!", ex);
      if (!isKeepScanning) {
        setIsAuth(false);
      }
      await NfcManager.cancelTechnologyRequest();
    } finally {
      await NfcManager.cancelTechnologyRequest();
    }
  };

EDIT: Have tried incorporating feedback from this issue (https://github.com/revtel/react-native-nfc-manager/issues/408) but no dice yet.

github-actions[bot] commented 4 months ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] commented 4 months ago

This issue was closed because it has been stalled for 5 days with no activity.