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

Get tag UID before Write action

Open cavasinf opened this issue 1 year ago • 5 comments

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())

cavasinf avatar Jan 18 '24 15:01 cavasinf

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 Apr 18 '24 01:04 github-actions[bot]

Get out of here!

cavasinf avatar Apr 18 '24 10:04 cavasinf

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

Get out of here!

cavasinf avatar Jul 18 '24 06:07 cavasinf