Develop Secure Code
NFCService Constants
NFCService Data Types
getNFCService()
isAvailable()
read()
write()
erase()
createTextRecord()
createUriRecord()
read(options)Reads an NFC tag and returns the data read from it.
1import { getNFCService } from 'lightning/mobileCapabilities';
2read(options?: NFCServiceOptions): Promise<Object>;options—(Required) An NFCServiceOptions object to configure the NFCService request.A Promise object that resolves to an array containing a single NFCMessage object.
A rejected promise returns a NFCServiceFailure.
Use this function to read data from an NFC tag.
1myNFCService
2 .read(options)
3 .then((readText) => {
4 this.results.records.parsed.payload = readText;
5 })
6 .catch((error) => {
7 this.readText = [];
8 console.error("Error code: " + error.code);
9 console.error("Error message: " + error.message);
10 });NFCMessage object instead of just the NFCMessage object is intentional. It’s to make extensibility updates easier, in case future enhancements to NFCService include the ability to read multiple NFC tags.catch clause.NFCServiceFailure.code value of USER_DISMISSED.See Also