revtel / react-native-nfc-manager

React Native NFC module for Android & iOS
MIT License
1.32k stars 312 forks source link

Get tag UID before Write action #693

Open cavasinf opened 5 months ago

cavasinf commented 5 months ago

Is it possible to read and write at the same time and check the UID before writing?

I've tried this, but the id is empty:

NfcManager.requestTechnology(NfcTech.Ndef)
  .then(() => {
    // return NfcManager.getTag() // <-- If this is use, it double the NFC prompt with possible `cancelTechnologyRequest` call missing
    return NfcManager.ndefHandler.getNdefMessage()
  })
  .then((tag) => {
    console.log(tag?.id) // Result is null

    // <---- I want to check the UID here

    const bytes = Ndef.encodeMessage([Ndef.textRecord("Hello")])
    return NfcManager.ndefHandler.writeNdefMessage(bytes)
  })
  .then(() => {
    if (Platform.OS === "ios") {
      NfcManager.setAlertMessageIOS("Written")
    }
  })
  .finally(() => NfcManager.cancelTechnologyRequest())
github-actions[bot] commented 2 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.

cavasinf commented 2 months ago

Get out of here!