Re: [web-nfc] Move user activation to obtain permission (#449)

@marcoscaceres `scan` and `push` methods are tightly integrated with the Permissions API. See JS example below.

```js
const reader = new NDEFReader();
 
async function startScanning() {
  await reader.scan();
  reader.onreading = event => {
    /* handle NDEF messages */
  };
}
 
const nfcPermissionStatus = await navigator.permissions.query({ name: "nfc" });
if (permissionStatus.state === "granted") {
  // NFC access was previously granted, so we can start NFC scanning now.
  startScanning();
} else {
  // Show a "scan" button.
  document.querySelector("button").style.display = "block";
  document.querySelector("button").onclick = event => {
    // Prompt user to allow UA to send and receive info when they tap NFC devices.
    startScanning();
  };
}
```

-- 
GitHub Notification of comment by beaufortfrancois
Please view or discuss this issue at https://github.com/w3c/web-nfc/pull/449#issuecomment-564579377 using your GitHub account

Received on Wednesday, 11 December 2019 14:49:30 UTC