revtel / react-native-nfc-manager

React Native NFC module for Android & iOS
MIT License
1.33k stars 317 forks source link

cannot convert undefined value to object. #672

Closed aasharck closed 3 months ago

aasharck commented 9 months ago

Whenever I try to read an NFC tag/card. It shows me this error cannot convert undefined value to object.

Any solution for this?

crojasv90 commented 9 months ago

Maybe you are using expo Go and you do not have the plugin configured in the app.json. Expo GO In my case, only NFC works for me when I build the APK, but I use expo GO, with CLI it is not necessary to build.

aasharck commented 9 months ago

Nop. I am using react native cli. Also, I am trying to read from another device using HCE. One phone is Android 13 and the other is Android 10. I am able to read from Android 13 by using the Android 10 device, but not the other way around.

Not sure why

crojasv90 commented 9 months ago

It seems to me that it is an NFC permissions issue. Check that part for the android version.

aasharck commented 9 months ago

Thanks, I checked the permissions, But I don't see any problem there. NFC is allowed for the app on both phones

johncantrell97 commented 9 months ago

Are you getting this when trying to access the array ndefMessage on the returned tag? I have found that even though the TagEvent interface says it will always return an ndefMessage: NdefMessage[] it sometimes (~10-20%) does not actually contain the ndefMessage key.

For me this seems to happen randomly, not in any predictable sort of way. I assume it's some kind of read error?

Dug a little into the source and it seems like at least on ios, if there's an error reading the ndefMessage it doesn't propagate the error but just returns the tag without the message (like I'm seeing):

if (!error) {
   [rnTag setObject:[NfcManager convertNdefMessage:ndefMessage] forKey:@"ndefMessage"];
}

callback(@[[NSNull null], rnTag]);
aasharck commented 9 months ago

Yea exactly.

When I tried console logging "tag" variable, In the types attribute, ndef type was no found. Not sure why?

johncantrell97 commented 9 months ago

I believe it's due to an error reading the tag in native code that doesn't bubble up to the javascript.

kamatil-dev commented 7 months ago

692 @crojasv90 @johncantrell97 can you please help me?

github-actions[bot] commented 4 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.