Reputation: 1
**i m using react native nfc manager and reading a tag while reading a tag an error occurs frequently after one execution here is my code: **
async function readData() {
console.log('readData>>>>>>');
try {
console.log('try in read>>>>');
// register for the NFC tag with NDEF in it
await NfcManager.requestTechnology(NfcTech.Ndef, {
alertMessage: 'Hold your phone close to the NFC tag.',
});
// the resolved tag object will contain `ndefMessage` property
const tag = await NfcManager.getTag();
console.log('Tag found read', tag);
const payload = tag?.ndefMessage[0].payload;
//remove the language code from payload
const subPayload = payload?.slice(3, payload.length);
const decoded = Ndef.util.bytesToString(subPayload);
console.log('done', decoded);
const result = decoded.split('|');
if (result.length === 2)
Actions.asset({
title: `Asset Details`,
assetId: result[0],
assetTypeId: result[1],
screenNameValue: `Asset Details`,
});
NfcManager.cancelTechnologyRequest();
} catch (ex) {
NfcManager.cancelTechnologyRequest();
console.warn('Oops in Read!', ex);
} finally {
NfcManager.cancelTechnologyRequest();
}
}
Any suggestions will be appreciated.
Upvotes: 0
Views: 298