starti.app
API Reference

NFC Scanner

Read NFC (Near Field Communication) tags from the device. Supports checking for NFC hardware and permission status, starting and stopping scan sessions, and receiving tag data via events.

Access: startiapp.NfcScanner

Methods

isNfcSupported(): Promise<boolean>

Checks whether the device hardware supports NFC.

Returns: Promise<boolean>true if the device has NFC hardware, false otherwise.

Example:

const supported = await startiapp.NfcScanner.isNfcSupported();
if (!supported) {
  console.log("This device does not have NFC");
}

isNfcEnabled(): Promise<boolean>

Checks whether NFC is currently enabled in the device settings. A device may support NFC but have it turned off.

Returns: Promise<boolean>true if NFC is enabled, false otherwise.

Example:

const enabled = await startiapp.NfcScanner.isNfcEnabled();
if (!enabled) {
  console.log("Please enable NFC in your device settings");
}

startNfcScanner(): Promise<void>

Starts listening for NFC tags. Once started, the nfcTagScanned event fires each time a tag is read.

Example:

// Set up the event listener first
startiapp.NfcScanner.addEventListener("nfcTagScanned", (event) => {
  const records = event.detail;
  records.forEach(record => {
    console.log(`Type: ${record.mimeType}, Message: ${record.message}`);
  });
});

// Start scanning
await startiapp.NfcScanner.startNfcScanner();

stopNfcScanner(): Promise<void>

Stops listening for NFC tags.

Example:

await startiapp.NfcScanner.stopNfcScanner();

Events

nfcTagScanned

Fired when an NFC tag is successfully read. Contains an array of NDEF records from the tag.

Event data: NfcTagResult[] —An array of NDEF records found on the tag.

Example:

startiapp.NfcScanner.addEventListener("nfcTagScanned", (event) => {
  const records = event.detail;

  records.forEach(record => {
    console.log("MIME type:", record.mimeType);
    console.log("Message:", record.message);
    console.log("Type format:", record.typeFormat);
  });
});

Types

NfcTagResult

Represents a single NDEF record read from an NFC tag.

type NfcTagResult = {
  /** The MIME type of the record (e.g. "text/plain", "application/json"). */
  mimeType: string;

  /** The decoded message content of the record. */
  message: string;

  /** The NFC type name format (e.g. "NfcWellKnown", "Mime", "External"). */
  typeFormat: string;
};

Usage Patterns

Full NFC scan flow with capability checks

async function startNfcScan() {
  // Check hardware support
  const supported = await startiapp.NfcScanner.isNfcSupported();
  if (!supported) {
    alert("NFC is not supported on this device");
    return;
  }

  // Check if NFC is turned on
  const enabled = await startiapp.NfcScanner.isNfcEnabled();
  if (!enabled) {
    alert("Please enable NFC in your device settings");
    return;
  }

  // Listen for tags
  startiapp.NfcScanner.addEventListener("nfcTagScanned", (event) => {
    const records = event.detail;
    for (const record of records) {
      console.log(`Scanned: ${record.message} (${record.mimeType})`);
    }
  });

  // Start scanning
  await startiapp.NfcScanner.startNfcScanner();
  console.log("NFC scanner is active, hold a tag near the device");
}

Reading a URL from an NFC tag

startiapp.NfcScanner.addEventListener("nfcTagScanned", (event) => {
  const records = event.detail;
  const urlRecord = records.find(r => r.mimeType === "text/plain" || r.typeFormat === "NfcWellKnown");

  if (urlRecord) {
    window.location.href = urlRecord.message;
  }
});

await startiapp.NfcScanner.startNfcScanner();

On this page