createTextRecord(payload)

Given a text payload, this function creates a properly formatted NFCRecord to be written to an NFC tag.

Syntax 

1import { getNFCService } from 'lightning/mobileCapabilities';
2createTextRecord(payload: TextPayload): Promise<Object>;

Parameters 

  • payload-(Required) A TextPayload object, which contains the text to be converted to an NFC record.

Returns 

A Promise object that resolves to an NFCRecord object.

A rejected promise returns an NFCServiceFailure.

Usage 

Use this function to create and return an NFC record to use as a parameter for the write() function.

1myNFCService
2  .createTextRecord(payload)
3  .then((result) => {
4    this.newNFCRecord = result;
5  })
6  .catch((error) => {
7    console.error("Error code: " + error.code);
8    console.error("Error message: " + error.message);
9  });
  • If an error occurs, the error is returned via a rejected promise. Handle errors in a catch clause.
  • When the user cancels the operation, the promise is rejected with a NFCServiceFailure.code value of USER_DISMISSED.

See Also