How to use the react-native-nfc-manager.registerTagEvent function in react-native-nfc-manager

To help you get started, we’ve selected a few react-native-nfc-manager examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github whitedogg13 / react-native-nfc-manager / example / AndroidMifareClassic.js View on Github external
for (let i = 0; i < NfcManager.MIFARE_BLOCK_SIZE; i++) {
            data.push(0);
          }

          // Fill the block with our text, but don't exceed the block size
          for (let i = 0; i < this.state.textToWrite.length && i < NfcManager.MIFARE_BLOCK_SIZE; i++) {
            data[i] = parseInt(this.state.textToWrite.charCodeAt(i));
          }

          return NfcManager.mifareClassicWriteBlock(block, data);
        })
        .then(read)
    };

    this.setState({ isDetecting: true });
    NfcManager.registerTagEvent(tag => console.log(tag))
      .then(() => NfcManager.requestTechnology(NfcTech.MifareClassic))
      .then(() => NfcManager.getTag())
      .then(tag => {
        this.setState({ tag });
        return NfcManager.mifareClassicGetSectorCount();
      })
      .then(sectorCount => {
        this.setState({ sectorCount });
      })
      .then(() => {
        let sector = parseInt(this.state.sector);
        if (isNaN(sector)) {
          this.setState({ sector: '0' });
          sector = 0;
        }
github whitedogg13 / react-native-nfc-manager / example / App.js View on Github external
_startDetection = () => {
        NfcManager.registerTagEvent(this._onTagDiscovered)
            .then(result => {
                console.log('registerTagEvent OK', result)
            })
            .catch(error => {
                console.warn('registerTagEvent fail', error)
            })
    }
github whitedogg13 / react-native-nfc-manager / example / AndroidTechTestNdef.js View on Github external
_runTest = textToWrite => {
        const cleanUp = () => {
            this.setState({isTestRunning: false});
            NfcManager.closeTechnology()
            NfcManager.unregisterTagEvent();
        }

        const parseText = (tag) => {
            if (tag.ndefMessage) {
                return NdefParser.parseText(tag.ndefMessage[0]);
            }
            return null;
        }

        this.setState({isTestRunning: true});
        NfcManager.registerTagEvent(tag => console.log(tag))
            .then(() => NfcManager.requestTechnology(NfcTech.Ndef))
            .then(() => NfcManager.getTag())
            .then(tag => {
                console.log(JSON.stringify(tag));
            })
            .then(() => NfcManager.getNdefMessage())
            .then(tag => {
                let parsedText = parseText(tag);
                this.setState({tag, parsedText})
            })
            .then(() => NfcManager.writeNdefMessage(buildTextPayload(textToWrite)))
            .then(cleanUp)
            .catch(err => {
                console.warn(err);
                cleanUp();
            })
github bailabs / tailpos / src / container / PaymentContainer / nfc_manager_initialization.js View on Github external
export function register_tag_event(props, deviceId) {
  const nfc_props = {
    invalidateAfterFirstRead: true,
    isReaderModeEnabled: true,
  };
  const message = "Scanning NFC Card";
  showToast("Please Scan Card Now");
  NfcManager.registerTagEvent(
    tag => validate_tag_event(tag, props, deviceId),
    message,
    nfc_props,
  );
}