aboutsummaryrefslogtreecommitdiffstats
path: root/src/service
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/service/NFCWriter.jsx18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/service/NFCWriter.jsx b/src/service/NFCWriter.jsx
new file mode 100644
index 0000000..91ac978
--- /dev/null
+++ b/src/service/NFCWriter.jsx
@@ -0,0 +1,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