capawesome-team / capacitor-nfc

⚡️ Capacitor plugin for reading and writing NFC tags.
https://capawesome.io/plugins/nfc/
MIT License
74 stars 14 forks source link

bug: Application crashes if repeatedly trying to scan & fail #20

Closed andreialinstoica closed 1 year ago

andreialinstoica commented 1 year ago

Plugin version: 5.0.1

Platform(s): Android

Current behavior: Start scanning session then repeatedly tap the NFC tag on the NFC receiver. It will crash the application. Wrapping the write function in a try catch error will show the following error: java.io.IOException: Only one TagTechnology can be connected at a time.

Expected behavior: Exception will be thrown in scanSessionError listener

Steps to reproduce: Start scanning session then repeatedly tap the NFC tag on the NFC receiver.

Related code:

           Nfc.addListener('nfcTagScanned', async (event) => {
            await Nfc.format();
            await Nfc.write({ message: { records: [record] } });
            await Nfc.stopScanSession();
        });

        await Nfc.startScanSession();

Capacitor doctor:

Latest Dependencies:

  @capacitor/cli: 5.0.5
  @capacitor/core: 5.0.5
  @capacitor/android: 5.0.5
  @capacitor/ios: 5.0.5

Installed Dependencies:

  @capacitor/core: 5.0.4
  @capacitor/cli: 5.0.4
  @capacitor/android: 5.0.4
  @capacitor/ios: 5.0.4

[error] Missing <manifest package=""> attribute in app/src/main
andreialinstoica commented 1 year ago

Can be fixed by replacing the write method with:

Android

public void write(....) .... {
         try {
            ... original code
        } catch (Exception exception) {
            notifyScanSessionErrorListener(exception.getMessage());
        }
    }

Based on the looks of it (code), seems that on iOS this problem is not happening.

andreialinstoica commented 1 year ago

This does not reproduce on the latest version 5.0.2.