MozNFC.getNFCTag()

The getNFCTag() method of the MozNFC interface returns an NDEF tag interface (MozNFCTag object) used to interact with NFC Tags.

It currently only supports NFC Data Exchange Format (NDEF) compatible NFC tag types, but its functionality will be expanded soon.

Syntax

MozNFCTag getNFCTag(DOMString sessionId);

Example

This example gives an idea of how you can set your activity handler function, then receive a session token from the activity when the function runs and get the NFC tag by passing it to getNFCTag():

navigator.mozSetMessageHandler('activity', ndefDiscoveredHandler);

function ndefDiscoveredHandler(activity) {
  var data = activity.source.data;
  var tag = navigator.mozNfc.getNFCTag(data.sessionToken);
  console.log(tag instanceof MozNFCTag); // should print true
}

Parameters

sessionToken: The session token associates the web application with the NFC hardware. It's found in the incoming Web Activity's data.sessionToken property, as seen in the above example.

Returns

A MozNFCTag object.

Errors

If an invalid session token is passed to getNFCTag(), it throws the error "Unable to create NFCTag object, Reason:  Bad SessionToken".

Specifications

The NFC implementation in Gecko follows the NFC Forum specifications.

Browser compatibility

Supported in Firefox OS 2.0 for certified-apps.
Available in privileged apps as of Firefox OS 2.2.

See also

Document Tags and Contributors

Contributors to this page: wbamberg, fscholz, chrisdavidmills, teoli, lgarner
Last updated by: wbamberg,