NFCService Data Types

NFCService defines and uses several data types.

An object returned by an NFC read() operation.

Property NameTypeDescriptionExample
totalByteLengthNumberThe size, in number of bytes, of the data received by the read() operation.256
recordsNFCMessageRecord[]An array containing a single NFCMessageRecord object, which in turn contains the payload from the NFC tag.[NFCMessageRecord]
tagInfoNFCTagInfoThe metadata about the tag. See NFCTagInfo.{ serialNumber: "04:EE:A0:5A", isNdefWritable: false, ndefCapacity: 512 }

An object within an NFCMessage object, containing the metadata read from an NFC tag.

Property NameTypeDescriptionExample
serialNumberStringThe serial number of the tag.”04:EE:A0:5A”
isNdefWritableBooleanFor a tag that can contain NDEF data, indicates whether the tag’s NDEF data can be overwritten. If the tag doesn’t support NDEF, this value is null.false
ndefCapacityNumberThe maximum NDEF message size, in bytes, that the tag can hold. If the tag doesn’t support NDEF, this value is null.512

An object within an NFCMessage object, containing the payload read from an NFC tag.

Property NameTypeDescriptionExample
parsedNFCRecordContains the parsed values of the raw data read from the NFC tag. The parsing operation only occurs if the value of the typeNameFormat property on the NFCRecord object is “WELLKNOWN”. Otherwise, this property’s value is null.
rawNFCRecordContains the raw base64 data string read from the NFC tag.

An object containing one record of data from an NFC tag scan.

Property NameTypeDescriptionExample
typeNameFormatTypeNameFormatThe Type Name Format field of the payload, as defined by the NDEF specification.”WELLKNOWN” See TypeNameFormat for a list of possible values.
typeStringThe type of the payload, as defined by the NDEF specification.”T” (when payload is of type text); “U” (when payload is of type URI)
identifierStringThe identifier of the payload, as defined by the NDEF specification, or an empty string if no identifier data was present in the tag.
payloadStringThe content of the record, encoded in base64 format.”V2XigJlyZSBTYWxlc2ZvcmNlLCBG9tZXIgY29tcGFueS4”

An object containing raw text input, to be converted into an NFCRecord.

Property NameTypeDescriptionExample
textStringThe raw text payload to be converted.”We’re Salesforce, the customer company.”
langIdStringThe ISO 639-1 language ID of the text.”en”

An object containing configuration details for an NFC interaction.

Property NameTypeDescriptionExample
instructionTextStringOptional. Provides instructions to display in the user interface. Defaults to no text.”Hold your phone near the tag to read.”
successTextStringOptional. Provides a message to display in the user interface when an NFC operation is successfully completed. Defaults to no text.”Tag read successfully!”
allowEmptyTagsBooleanOptional. Indicates whether reading from an empty tag is considered an error. Defaults to false, so attempting to read an empty tag returns a TAG_EMPTY error. To get the tag metadata even for empty tags, set this property to true. The read() operation then returns an NFCMessage object whose tagInfo property is populated instead of a TAG_EMPTY error.true

An object representing an error that occurred when accessing NFCService features.

Property NameTypeDescription
codeNFCServiceFailureCodeA value representing the reason for an error. See NFCServiceFailureCode for the list of possible values.
messageStringA string value describing the reason for the failure. This value is suitable for use in user interface messages. The message is provided in English and isn’t localized.

See Also