This specification defines an API that provices access to the NFC(Near Field Communication) capabilities of the device.

Introduction

This section is non-normative

The NFC API defines a means for web developers to programmatically determine the NFC capabilities of the hosting device. The API is designed to be a compact and generic API that quickly and wirelessly exchange information between devices and accessories, NFC readers.

The NFC API can be used for a wide variety of web applications, including:

The following code snippet illustrates how to write NFC tag, for each MIME type:

			var mimeType = WriteForm.mimeType.value;
			var payload = WriteForm.payload.value;
			var record;
					
			if(mimeType == 'Text') {
				record = ndef.textRecord(payload, null);
			} else if(mimeType == 'URI') {
				record = ndef.uriRecord(payload, null);
			} else if(mimeType == 'MimeMedia') {
				record = ndef.mimeMediaRecord(mimeType, nfc.stringToBytes(payload));
			}
					
			Nfc.NfcManager.write(record, "onSuccess", "onException", true);
		

The following code snippet illustrates how to watch NFC tag information from the device:

			var tag = Util.toObject(result);
			var records = tag.ndefMessage || [];

			Nfc.NfcManager.watch("onSuccess", "onException", true);
					
			for(var i = 0; i < records.length; i++) {
				var record = records[i];
				var payload;
				var recordType = Nfc.bytesToString(record.type);
						
				if(recordType == 'T') {
					var langCodeLength = record.payload[0];
					var text = record.payload.slice((1 + langCodeLength), record.payload.length);
					payload = Nfc.bytesToString(text);
					alert("Plain Text:"+payload);
				} else if(recordType == 'U'){
					payload = Nfc.bytesToString(record.payload);
					alert('URL:' + payload);
				} else if(recordType == 'text/x-vCard') {
					payload = Nfc.bytesToString(record.payload);
					alert(payload);
				} else {
					payload = Nfc.bytesToString(record.payload);
					alert(payload);
				}
			}
		

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.

Terminology

The Function interface represents a function in the scripting language being used as defined in [[!HTML5]].

The concepts queue a task and fires a simple event are defined in [[!HTML5]].

The terms event handlers and event handler event types are defined in [[!HTML5]].

Security and privacy considerations

The API defined in this specification is used to determine the battery status of the hosting device. The information disclosed has minimal impact on privacy or fingerprinting, and therefore is exposed without permission grants. For example, authors cannot directly know if there is a battery or not in the hosting device.

NavigatorNFC Interface

The NavigatorNFC interface is exposed on the Navigator object.

readonly attribute NFCManager nfc
The root node from which the NFC functionality can be accessed.

NFCManager interface

@@TBD

User Interaction Guidelines

@ to be included

Use Cases and Requirements

Use Cases

Use Case 1:

Requirements

This interface:

Features for Future Consideration

This is a list of features that have been discussed with respect to this version of the API but for which it has been decided that if they are included it will be in a future revision.

Acknowledgements

The editors would like to thank the input and the feedback received from W3C DAP members to date ...