Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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;
}
_startDetection = () => {
NfcManager.registerTagEvent(this._onTagDiscovered)
.then(result => {
console.log('registerTagEvent OK', result)
})
.catch(error => {
console.warn('registerTagEvent fail', error)
})
}
_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();
})
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,
);
}