revtel / react-native-nfc-manager

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

Can't retrieve tag information with background tag on IOS #715

Open ImperialCrowns opened 2 months ago

ImperialCrowns commented 2 months ago

Hey !

I wrote the following code :

const initNFC = () => {
  const onBackgroundTag = async (tag: TagEvent | null) => {
    console.log('onBackgroundTag', tag);
  };

  const initalizeBackgroundTag = async () => {
    // changed
    await NfcManager.start();

    const bgTag = await NfcManager.getBackgroundTag();
    onBackgroundTag(bgTag);

    // listen to other background tags after the app launched
    NfcManager.setEventListener(NfcEvents.DiscoverBackgroundTag, onBackgroundTag);
  };
  initalizeBackgroundTag();
};

function App() {
  initNFC();
  return (
    <View>
      <Text>Hello World</Text>
    </View>
  );
}

export default App;

I'm trying to retrieve tag informations when reading tag in background but the return value of NfcManager.getBackgroundTag is always null. What am I doing wrong ? Is there something I miss ? Is it possible to do it ?

Environment:

I've already tried many solutions proposed in previous issues, and it don't work.

BhavyaCodeAlchemy commented 2 months ago

It's Working fine in android ?

ImperialCrowns commented 2 months ago

Yes, on Android it works perfectly.

gigeos commented 2 months ago

Same for me

I can't retrieve the tagId when the application is launched in background on iOS thanks to the little NFC notification that appears when a tag is touched.