Here are some possible use cases:
An example of use is provided below:
var hello = new NDEFRecordText("hello world", "en-US", "UTF-8"); navigator.nfc.ontagfound = function(e) { window.console.log('NFC Tag found!'); var tag = e.tag; tag.writeNDEF(new NDEFMessage([hello])); } navigator.nfc.startPoll().catch( function(e) { window.console.error(e); });
This specification defines conformance criteria that apply to a single product: the user agent that implements the interfaces that it contains.
Implementations that use ECMAScript to implement the APIs defined in this specification MUST implement them in a manner consistent with the ECMAScript Bindings defined in the Web IDL specification [[!WEBIDL]], as this specification uses that specification and terminology.
The
EventHandler
interface represents a callback used for event
handlers as defined in [[!HTML5]].
The concepts queue a task and fire a simple event are defined in [[!HTML5]].
The terms event handler and event handler event types are defined in [[!HTML5]].
The Event
interface and the
Promise
interface as well as the concept of a
resolver
are defined in [[!DOM4]].
A NFC tag is a passive, unpowered NFC device. The NFC tag is powered by magnetic induction when an active NFC device is in close vicinity. A NFC tag contains a single NDEF message.
A NDEF message encapsulates one or more application-defined NDEF records. NDEF stands for NFC Forum Data Exchange Format, a lightweight binary message format. NDEF messages can be stored on a NFC tag or exchanged between NFC-enabled devices.
A NDEF record has a maximum payload of 2^32-1 bytes. The record also contains information about the payload size, type, and an optional identifier.
Navigator
objectThe NFCManager interface is exposed on [[!HTML]]'s
Navigator
object.
The NFCManager interface defines access to NFC functionality and offers methods to control local NFC behavior like polling for targets.
Promise
to notify
the caller that the NFC hardware is now polling. The resulting promise is
fulfilled even if the device was already polling, as state changes are tracked
with the onpollstart
and onpollstop
handlers.Promise
to notify the caller that the NFC hardware
stopped polling. This method may power off the NFC hardware, depending on
the underlying implementation.pollstart
event is dispatched.pollstop
event is dispatched.tagfound
event of type NFCTagEvent
MUST
be fired whenever a new NFCTag is detected by the NFC manager.
The tag
property of the event MUST contain the
corresponding NFCTag object.taglost
event is dispatched.peerfound
event of type NFCPeerEvent
MUST
be fired whenever a new NFCPeer is detected by the NFC manager.
The peer
property of the event MUST contain the
corresponding NFCPeer object.peerlost
event is dispatched.The following are the event handlers (and their corresponding event handler types) that MUST be supported as attributes by the NFC object.
event handler | event name | event type | short description |
---|---|---|---|
onpollstart |
pollstart |
simple event | fired when the polling state changes to
true |
onpollstop |
pollstop |
simple event | fired when the polling state changes to
false |
ontagfound |
tagfound |
NFCTagEvent with tag property set to
the new NFCTag object. |
detect a new NFCTag |
ontaglost |
taglost |
simple event | fired when the NFCTag detected by the
adaptor moves out of range. |
onpeerfound |
peerfound |
NFCPeerEvent with peer property set to
the new NFCPeer object. |
detect a new NFCPeer |
onpeerlost |
peerlost |
simple event | fired when the NFCPeer detected by the
adaptor moves out of range. |
Promise
that will notify the caller with the result of
the operation, which is a NDEFRecord.Promise
to notify the caller about the operation
success or failure.
Promise
to notify the caller about the operation
success or failure.
Promise
to notify the caller about
the operation success or failure.
"wifi"
or "bluetooth"
pairing.messageread
event of type NDEFMessageEvent
MUST
be fired whenever a new NDEFMessage is sent by the peer device.
The message
property of the event MUST contain the
corresponding NDEFMessage object.The following are the event handlers (and their corresponding event handler types) that MUST be supported as attributes by the NFCPeer object.
event handler | event name | event type | short description |
---|---|---|---|
onmessageread |
messageread |
NDEFMessageEvent with message property set to
the new NDEFMessage object. |
fired when a NDEFMessage is sent by the peer device.
|
NDEFRecord
objects part of
the NDEF message. Otherwise it MUST return an empty list.Promise
to notify the caller with the result of
the operation, which is of type byte[]
i.e. a Javascript
Array of Number objects. Promise
to notify the caller with the result of
the operation, which is of type byte[]
i.e. a Javascript
Array of Number objects. The attribute recordType
can have the following values:
The attribute action
can have the following values:
The attribute handoverType
can have the following values:
The editors would like to thank Jaehyun Park and Taehee Lee of Samsung for their work on the initial API design. We would also like to thank the members of the W3C SysApps group for their help on the API specification process, and the members of the W3C NFC group for their feedback on this API.