0

I am trying to add the NFC feature in my react-native app by using react-native-NFC-Manager and it is working fine. But the issue is at the first time I am unable to read/write the NFC card. For the first time, I need to write a new tag by using the NFC Tool app to convert 'NdefFormatable' to 'Ndef' otherwise I am not able to read/write the NFC card

I have used this code to write data:

await NfcManager.requestTechnology(NfcTech.Ndef, {
      alertMessage: 'Ready to write some NDEF',
    });

    const bytes = Ndef.encodeMessage([Ndef.textRecord('Hello NFC')]);

    if (bytes) {
      await NfcManager.ndefHandler // Step2
        .writeNdefMessage(bytes); // Step3

      if (Platform.OS === 'ios') {
        await NfcManager.setAlertMessageIOS('Successfully write NDEF');
      }
    }

Is there any solution to this issue?

Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
krishna
  • 1
  • 1

1 Answers1

0

A Two part answer.

For Android if you code did not just ask for detection already formatted tags with the NfcManager.requestTechnology(NfcTech.Ndef, and instead used the more basic NfcManager.setEventListener(NfcEvents.DiscoverTag, (tag) => { method of detecting Tags then you can write an unformatted Tag (as writing formats it)

For iOS is a lot more complicated as it does not allow writing to unformatted Tags https://github.com/revtel/react-native-nfc-manager/blob/main/FAQ.md#ios-cannot-write-ndef-into-nfc-tags

As a background in simple terms an unformatted Ndef formatted Tag has a capability container record but no TLV entry, formatting adds a blank TLV entry, where as writing add a TLV entry with a non blank TLV entry.

Andrew
  • 8,198
  • 2
  • 15
  • 35
  • it is okay with already formatted tags. I have got an issue only with the new unformatted tag. I tried with setEventListener but it did not work. When i try to write an error 'unsupported tag api' is returned. my tag info is: { "techType":[" android.nfc.tech.NfcA ", "android.nfc.tech.MifareClassic", "android.nfc.tech.NdefFormatable"], "id":"0A18C400","ndefStatus":{"status":1, "capacity":0}} i have checked this app and this app also have the same issue https://github.com/revtel/react-native-nfc-rewriter – krishna Nov 12 '21 at 13:16
  • As you seem to be using a non standard Mifare Classic Tag, some phones will not support this Tag at all and getting Ndef data on to them is again a non standard manufacturer specific mechanism. I would recommend that you don't use this type of Tag for Ndef Data at all but use a standards compliant NFC Tag instead. You could still write Ndef data to it on some phones but you would have to use the low level `mifareClassicHandlerAndroid` or even lower `nfcAHandler` to implement formatting yourself. – Andrew Nov 12 '21 at 18:00