Don't able to get the string value of NFC card in react native

439 Views Asked by At

Form the last 3 days I trying to get the string values from my NFC card but I can't. when I scan the card then the "getTag()" function get shows some values in the log but in that value, I can't find the string which is stored in the tag.

Here is my Code which I tried first:-

    try {
        NfcManager.start();
        await NfcManager.requestTechnology(NfcTech.NfcA);
        const tag1 = await NfcManager.getTag();

        console.log(" ~ file: NFC.js ~ line 41 ~ readTags ~ tag", JSON.stringify(tag1))
    } catch (ex) {
        console.warn('Oops!', ex);
    }

Code I tried a second time: -

   try {
        let tech = Platform.OS === ' ios ' ? NfcTech.MifareIOS : NfcTech.NfcA;
        let resp = await NfcManager.requestTechnology(tech, {
            alertMessage: " Ready for magic "
        });
        let i;
        NfcManager.start();
        let cmd = Platform.OS === 'ios' ? NfcManager.sendMifareCommandIOS : NfcManager.transceive;
        resp = await cmd([0x3A, 4, 4])
        let payloadLength = parseInt(resp.toString().split(",")[1]);
        let payloadPages = Math.ceil(payloadLength / 4);
        let startPage = 5;
        let endPage = startPage + payloadPages - 1;

        resp = await cmd([0x3A, startPage, endPage]);
        let bytes = resp.toString().split(",");
        console.log(" ~ file: NFC.js ~ line 51 ~ readTags ~ bytes", bytes)
        let text = "";

        for (let i = 0; i < bytes.length; i++) {
            if (i < 5) {
                continue;
            }
        }
        if (parseInt(bytes[i]) === 254) {
            return;
        }

        text = text + String.fromCharCode(parseInt(bytes[i]));
        console.log(" ~ file: NFC.js ~ line 61 ~ readTags ~ text", JSON.stringify(text))


    } catch (ex) {
        console.warn('Oops!', ex);
    }

Card Info: This is the card information which I am using.

enter image description here

Can anyone help me to get rid of this problem?

0

There are 0 best solutions below