import React from 'react'; import { View, Text, TouchableOpacity, } from 'react-native'; import NfcManager, {Ndef, NfcTech} from '../NfcManager'; function buildUrlPayload(valueToWrite) { return Ndef.encodeMessage([ Ndef.uriRecord(valueToWrite), ]); } class AppV2Ndef extends React.Component { componentDidMount() { NfcManager.start(); } componentWillUnmount() { this._cleanUp(); } render() { return ( NFC Demo Test Ndef Cancel Test ) } _cleanUp = () => { NfcManager.cancelTechnologyRequest().catch(() => 0); } _testNdef = async () => { try { let resp = await NfcManager.requestTechnology(NfcTech.Ndef, { alertMessage: 'Ready to write some NFC tags!' }); console.warn(resp); let ndef = await NfcManager.getNdefMessage(); console.warn(ndef); let bytes = buildUrlPayload('https://www.revteltech.com'); await NfcManager.writeNdefMessage(bytes); console.warn('successfully write ndef'); await NfcManager.setAlertMessageIOS('I got your tag!'); this._cleanUp(); } catch (ex) { console.warn('ex', ex); this._cleanUp(); } } } export default AppV2Ndef;