The records
property of NDEFMessage
interface represents a list of NDEFRecord
s present in the NDEF message.
A list of NDEFRecord
object that represent data recorded in the message.
The following example shows how to read the contents of an NDEF message. It first sets up an event handler for onreading
, which is passed an instance of NDEFReadingEvent
. An NDEFMessage
object is returned from NDEFReadingEvent.message
. It loops through message.records
and processes each record based on its message type. The data member is a DataView
, which allows handling data encoded in UTF-16.
ndefReaderInst.onreading = (event) => {
const ndefMessage = event.message;
for (const record of ndefMessage.records) {
console.log(`Record type: ${record.recordType}`);
console.log(`MIME type: ${record.mediaType}`);
console.log(`Record id: ${record.id}`);
switch (record.recordType) {
case "text":
break;
case "url":
break;
default:
}
}
};