Skip to content

Commit f467f09

Browse files
committed
add example and use case for readonly in explainer
Signed-off-by: Zoltan Kis <[email protected]>
1 parent 5c68261 commit f467f09

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

EXPLAINER.md

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,28 @@ The API does not support controlling who can change the content on an NDEF
5757
tag. However, the API supports making an NDEF tag permanently read-only, see the
5858
[examples](https://w3c.github.io/web-nfc/#make-an-nfc-tag-permanently-read-only).
5959

60+
```js
61+
const ndef = new NDEFReader();
62+
try {
63+
await ndef.write({
64+
records: [
65+
{
66+
recordType: "url",
67+
data: "https://www.louvre.fr/en/explore/visitor-trails/the-louvre-s-masterpieces"
68+
},
69+
{
70+
recordType: "text", data: "The Louvre's Masterpieces"
71+
}
72+
]
73+
});
74+
console.log("NFC tag written.");
75+
await ndef.makeReadOnly();
76+
console.log("NFC tag has been made permanently read-only.");
77+
} catch (error) {
78+
console.log(`NDEF operation failed: ${error}`);
79+
}
80+
```
81+
6082
## API shape and examples
6183

6284
The API has gone through multiple iterations and have had feedback from Mozilla,
@@ -293,8 +315,11 @@ only relevant for scans.
293315
### Added the `makeReadOnly()` method
294316

295317
Justified in [issue 558](https://github.com/w3c/web-nfc/issues/558) and by feedback
296-
received on Twitter. It seems like web developers would like to be able to
297-
"lock" NFC tags with Web NFC. [PR 632](https://github.com/w3c/web-nfc/pull/632/files)
318+
received on Twitter. Developers would like to be able to "lock" NFC tags with
319+
Web NFC, in order to prevent further changes of the information written on tag,
320+
for instance in the case of information tags in a museum or other public points
321+
of interest.
322+
[PR 632](https://github.com/w3c/web-nfc/pull/632/files)
298323
addressed that need by introducing an abortable `makeReadOnly()` method on the
299324
`NDEFReader` object.
300325

0 commit comments

Comments
 (0)