aboutsummaryrefslogtreecommitdiffstats
path: root/src/service/NFCWriter.jsx
blob: 91ac9782561673320b4647015003c2c0124af045 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
const writeToNFC = async url => {
  if ('NDEFReader' in window) {
    try {
      const ndef = new window.NDEFReader()
      await ndef.write({
        records: [{ recordType: 'url', data: url }],
      })
      alert('URL written to NFC tag successfully!')
    } catch (error) {
      console.error('Error writing to NFC tag:', error)
      alert('Error writing to NFC tag. Please try again.')
    }
  } else {
    alert('NFC is not supported by this browser.')
  }
}

export default writeToNFC