react-native-nfc-manager icon indicating copy to clipboard operation
react-native-nfc-manager copied to clipboard

Ndef not writing the empty tag in android only

Open Nardeep opened this issue 1 year ago • 4 comments

When tag is empty , then ndef.writeNdefMessage is not working its throwing error : [Error: unsupported tag api]

we are using below code: const writeDataToNfcTag = async (data) => { console.log('data-=-=-',data); try { await NfcManager.requestTechnology(NfcTech.Ndef, { alertMessage: 'Ready to write some NDEF', }); const bytes = Ndef.encodeMessage([Ndef.textRecord(data)]); console.log('bytes-=-=',bytes); if (bytes) { try{ await NfcManager.ndefHandler.writeNdefMessage(bytes);

            if (Platform.OS === 'ios') {
                await NfcManager?.setAlertMessageIOS('Successfully write NDEF');
            }
         }catch(err){
            console.log('writeError-=-',err);
         }

        }

    } catch (error) {
        console.error('Error writing data to NFC tag:', JSON.stringify(error));
    } finally {
        await NfcManager.cancelTechnologyRequest();
    }
}


After debugging the android code we found that when tag is empty then its not detecting  techRequest.
Ndef ndef = (Ndef)techRequest.getTechHandle();
ndef is coming null. So please check why its happening 

Nardeep avatar Mar 27 '24 14:03 Nardeep

Same issue on our side. Did you find a solution / workaround?

K-Leon avatar Apr 07 '24 20:04 K-Leon

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] avatar Jul 07 '24 01:07 github-actions[bot]

@K-Leon Hi , we resolved this issue. The issue is in technology type we added the technology in requestTechnology and use the correct write function according to nfc technology. Here is the below code: let technology = await NfcManager.requestTechnology([NfcTech.NdefFormatable, NfcTech.Ndef],

let promise = (technology == "NdefFormatable" ? NfcManager.ndefFormatableHandlerAndroid.formatNdef(bytes) : NfcManager.ndefHandler.writeNdefMessage(bytes))

Nardeep avatar Jul 08 '24 06:07 Nardeep

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] avatar Oct 07 '24 02:10 github-actions[bot]

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

github-actions[bot] avatar Oct 23 '24 02:10 github-actions[bot]