revtel / react-native-nfc-rewriter

NFC open reader app in React Native
MIT License
193 stars 85 forks source link

Error: java.io.IOException while writing NfcManager.ndefHandler.writeNdefMessage(bytes) #38

Open pruthvirajkarurcodewave opened 2 years ago

pruthvirajkarurcodewave commented 2 years ago

Hi I am trying to read an NFC and Write it back in android Samsung Galaxy M51. and tried in multiple other android phones as well. Same happens even in iOS devices.

While it works for ideal case when the user taps first time for reading and takes the tag away. Then brings the tag near again to Write it back.

In other case when the user keeps the phone on top of the NFC tag and then tries to write it to the tag while the tag is still under the phone touching it, then sometimes the data in the tag is getting clear and we are getting "Error: java.io.IOException" , or "unsupported tag api" or "Tag is not ndef" errors.

When this "Error: java.io.IOException" comes, the data from the NFC tag get cleared out.

### The issue is in NfcProxy.js in writeNdef method.

Please suggest on how to resolve this error.

Below is the code used:

await NfcManager.requestTechnology(NfcTech.Ndef);
    const bytes = Ndef.encodeMessage([Ndef.textRecord('Hello NFC')]);
    if (bytes) {
      await NfcManager.ndefHandler // STEP 2
        .writeNdefMessage(bytes); // STEP 3
       }
Versions used:
    "react-native": "0.68.1",
    "react-native-nfc-manager": "^3.13.2",
NFC type:
NFC type4A - ISO/IEC 14443A
Tech List: 
android.nfc.tech.IsoDep
android.nfc.tech.NfcA
android.nfc.tech.Ndef