revtel / react-native-nfc-manager

React Native NFC module for Android & iOS
MIT License
1.32k stars 312 forks source link

tag.ndefMessage is undefined #688

Closed mickytroxxy closed 3 months ago

mickytroxxy commented 6 months ago

Hello my fellow devs, I have been stuck for almost 48 hours now on the tag.ndefMessage which is being undefined, but the tag itself has Object { "id": "0E9A3923200B20", "techTypes": Array [ "android.nfc.tech.IsoDep", "android.nfc.tech.NfcA", ], }

Below is my code, I tried using rn-cli then moved to eas-build with no luck

import React, { useEffect, useState } from 'react' import { Text, View, TouchableOpacity } from 'react-native'; import { LinearGradient } from 'expo-linear-gradient';

import * as Animatable from 'react-native-animatable'; import Icon from '../components/ui/Icon'; import { colors } from '../constants/Colors'; import { useRouter } from 'expo-router'; import { GlobalStyles } from '../styles'; import NfcManager, {NfcTech} from 'react-native-nfc-manager'; NfcManager.start(); const SplashScreen = () => { const router = useRouter(); const [nfcData, setNfcData] = useState(null); useEffect(() => { NfcManager.start(); return () => { NfcManager.cancelTechnologyRequest(); }; }, []);

const readNdef = async () => { try { console.log('Waiting for the read'); await NfcManager.requestTechnology([ NfcTech.MifareIOS, NfcTech.Ndef, NfcTech.Iso15693IOS, NfcTech.IsoDep, NfcTech.NfcA, NfcTech.NfcB, NfcTech.NfcF, NfcTech.NfcV, NfcTech.FelicaIOS, NfcTech.MifareClassic, ]);

  const tag = await NfcManager.getTag();
  console.warn('Tag found', tag);
  if (tag.ndefMessage) {
    tag.ndefMessage.forEach((record) => {
      console.log('NDEF Record:', record);
      const payload = Ndef.text.decodePayload(record.payload);
      console.log('Record Payload:', payload);
    });
  } else {
    console.warn('Tag does not contain NDEF message');
  }
} catch (ex) {
  console.warn('Oops!', ex);
} finally {
  NfcManager.cancelTechnologyRequest();
}

}; return(

All For Your Beauty Request for hair stylist, coiffurist and buy exotic cosmetic products readNdef()}> Get Started

) } export default SplashScreen

Please help

siash1 commented 6 months ago

Same problem please help. It's working on Android but not on iOS for me

github-actions[bot] commented 3 months ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] commented 3 months ago

This issue was closed because it has been stalled for 5 days with no activity.