Develop Secure Code
NFCService Constants
NFCService Data Types
getNFCService()
isAvailable()
read()
write()
erase()
createTextRecord()
createUriRecord()
write(options)Write text to an NFC tag.
1import { getNFCService } from 'lightning/mobileCapabilities';
2write(
3 payloads: NFCRecord[],
4 options?: NFCServiceOptions
5): Promise<Object>;NFCRecord objects containing the raw bytes to be written.NFCServiceOptions object to configure the NFCService request.If successful, the OS returns a Promise object that resolves to null. If unsuccessful, the OS returns a Promise object that rejects to NFCServiceFailure.
Use this function to write text to an NFC tag.
1myNFCService
2 .write(payloads, options)
3 .then(() => {
4 console.log("Payload was written successfully!");
5 })
6 .catch((error) => {
7 console.error("Error code: " + error.code);
8 console.error("Error message: " + error.message);
9 });catch clause.NFCServiceFailure.code value of USER_DISMISSED.The caller is responsible for ensuring that the payload of the NFCRecord object is correctly formatted, per NFC specifications. To help with this, we’ve provided two helper functions, createTextRecord() and createUriRecord(). By using these functions, you can convert your text or URI payload to an NFC record first, and then pass those records to the write() method to be written to the tag.
Note
See Also