const handleRead = async() => {
addLog("User clicked scan button");
if ('NDEFReader' in window) {
console.log('NDEFReader is supported');
} else {
console.log('NDEFReader is not supported');
}
try{
const ndef = new window.NDEFReader();
await ndef.scan();
addLog("> Scan started");
ndef.addEventListener("readingerror", () => {
addLog("Argh! Cannot read data from the NFC tag. Try another one?");
});
ndef.addEventListener("reading", ({ message, serialNumber })=>{
addLog(`> Serial Number: ${serialNumber}`);
addLog(`> Records: (${message.records.length})`);
const decoder = new TextDecoder();
for(const record of message.records){
if(record.recordType === "text")
{
const text = decoder.decode(record.data);
addLog(`> Record text: ${text}`);
}
}
}
);
}catch(error){
addLog("Error: " + error)
}
}
when i try to change const ndef = new NDEFReader(); it will show the error: NDEFReader is not ‘NDEFReader’ is not defined no-undef. But if i keep this, in the logerr shows NDEFReader is not a constructor.
I had google it but solution didnt work. I have been add the https in to my react project