revtel / react-native-nfc-manager

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

Scan issues on iOS 13.3.1 #289

Closed Valandur closed 3 years ago

Valandur commented 4 years ago

Following the example to read ndef tags I have added the following code

await NfcManager.start();
NfcManager.setEventListener(NfcEvents.DiscoverTag, (e: TagEvent) => {
    const str = Buffer.from(e.ndefMessage[0].payload).toString('utf8');
    console.log(str);
});
await NfcManager.registerTagEvent();

during my component initialization.

This works perfectly on Android devices, but produces a warning in the logs on iOS: [CoreNFC] 00000002 80129180 -[NFCNDEFReaderSession _callbackDidBecomeActive]:228 Delegate does not implement -readerSessionDidBecomeActive: method

The scanning system overlay for iOS shows up, but it never scans any tags.

If I copy and paste the lines 260-262 of ios/NfcManager.m and rename the method to readerSessionDidBecomeActive then the warning in the logs goes away, and the scanning also works.

I'm not sure if I ran into an actual bug (possibly with older versions of iOS? Target deployment is set to iOS 9.0 for my project) or if I misconfigured something.

gbettinazzi commented 4 years ago

Same problem here, also targetting iOS 9.0

gbettinazzi commented 4 years ago

In my case it was my mistake because the tag I was using was empty

Valandur commented 4 years ago

Considering it works on Android I don't think an empty tag is the issue, at least for me.

whitedogg13 commented 4 years ago

Hi @Valandur , I think @gbettinazzi is right. Tags contain no valid NDEF records will not be discovered by registerTagEvent, since we use NFCNDEFReaderSession under the hood for this case.

Can you try it again with tags contain valid NDEF message?

Valandur commented 4 years ago

Hi, sorry for the confusion but I am actually using a tag with data. I was just thinking that the fact that it has data shouldn't matter for the firing of the event, but it possibly does?

The tags I'm reading do contain a valid NDEF message, and I also receive that data on Android. On iOS I only receive the data when adding the fix I posted above.

Valandur commented 4 years ago

I believe to have found the cause for this issue. I had to set platform :ios, '11.0' in my Podfile, not just in the main project. Now it seems to work, even without the additional line changes I mentioned.

github-actions[bot] commented 3 years 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 years ago

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