Develop Secure Code
NFCService Constants
NFCService Data Types
getNFCService()
isAvailable()
read()
write()
erase()
createTextRecord()
createUriRecord()
erase(options)Erase the contents of an NFC tag.
Using erase() is an inherently dangerous action, as it allows data to be irreversibly deleted. Use caution when using this functionality in your component. At an absolute minimum, consider adding a confirmation window for your users that clearly states the outcome of the action, with an option for them to cancel if they wish.
Warning
The erase() function can only be performed on writable NFC tags. Attempting this function on a read-only NFC tag will result in an error.
Note
1import { getNFCService } from 'lightning/mobileCapabilities';
2erase(options?: NFCServiceOptions): Promise<Object>;options—(Required) An 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 erase data from an NFC tag.
1myNFCService
2 .erase(options)
3 .then(() => {
4 console.log("Data erased 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.See Also