revtel / react-native-nfc-rewriter

NFC open reader app in React Native
MIT License
193 stars 85 forks source link

NfcProxy.readTag() = ERROR #40

Closed maxencewrt closed 2 years ago

maxencewrt commented 2 years ago

Hello :)

First of all thanks a lot for this amazing repo ! I have a quick question, when I launch the following code:


  function renderNfcButtons() {
    return (
      <View
        style={{
          alignItems: 'stretch',
          alignSelf: 'center',
        }}>
        <Button
          mode="contained"
          color="black"
          onPress={async () => {
            console.log("before scan")
            const tag = await NfcProxy.readTag();
            console.log("scanned")
            if (tag) {
              database()
                .ref('/Artworks/' + tag.id)
                .on('value', snapshot => {
                  const dataGet = snapshot.val();
                  if (dataGet != undefined) {
                    navigation.navigate('AuthSuccess', {tag});
                  } else {
                    navigation.navigate('AuthFailed');
                  }
                });
            }
          }}>
          Start Authentication
        </Button>
      </View>
    );
  }

I have the following issue :

image

It seems impossible to me to scan a tag. Have you any idea ?

Thanks a lot !

maxencewrt commented 2 years ago

It seems the issue is there :

  readTag = withAndroidPrompt(async () => {
    let tag = "toto";

    try {
      await NfcManager.requestTechnology([NfcTech.Ndef]);

      tag = await NfcManager.getTag();
      tag.ndefStatus = await NfcManager.ndefHandler.getNdefStatus();

      if (Platform.OS === 'ios') {
        await NfcManager.setAlertMessageIOS('Success');
      }
    } catch (ex) {
      // for tag reading, we don't actually need to show any error
      console.log(ex);
    } finally {
      NfcManager.cancelTechnologyRequest();
    }

    return tag;
  });

Have you any idea why the TRY don't work and I directly go in catch ?

maxencewrt commented 2 years ago

Just need to upgrade nfc package