Tuesday, August 9, 2022
HomeiOS Developmentandroid - React native: requestTechnology known as provided that the app is...

android – React native: requestTechnology known as provided that the app is introduced from background to foreground

I am currently working on a simple app for scanning, reading data from an NFC card (in my case a Mifare NFC card) and displaying in on the screen. I have built it using this example.

The app should work both on Android and iOS, but for the moment, I have tested it only on an android device (an Oppo device with NFC capablities and developer mode activated).

At the launch of the app, everything seems to be working fine, the NfcManager has been successfully started, but there is an issue when the app tries to request the technology for reading the card, namely, I have to bring the app first in the background and then again in the foreground so that the message requestTechnology success is displayed, otherwise, it's simply not called.

After this, the promise NfcManager.getTag() gets rejected with the error message: no reference available.

Here is my code:

let tech = Platform.OS === 'ios' 
    ? NfcTech.MifareIOS : [NfcTech.MifareClassic, NfcTech.NfcA, NfcTech.IsoDep, NfcTech.Ndef];
let resp = await NfcManager.requestTechnology(tech, {
        alertMessage: 'Ready to do some custom Mifare cmd!'
      .then(() => alert('requestTechnology success')) // this gets called only after bringing the app to the foreground
      .catch(() => console.warn('reuqestTechnology error'));
let tag = await NfcManager.getTag(); // this line throws the no reference available error

Does anyone know why does the app needs to be brought to the background so that the technology is requested? And second, does the fail of the getTag() method have anything to do with it?

I hope anyone can help me with this issue, I have been struggling with this problem for quite some time and I haven't found any solution.



Please enter your comment!
Please enter your name here

Most Popular

Recent Comments