semlette / nfc_in_flutter

Cross-platform flutter plugin for reading and writing NFC tags. Not maintained anymore - not looking for new maintainer, fork instead.
MIT License
119 stars 119 forks source link

iOS NFC Read - Once: False (MultiScan) - Not Activating Done #86

Open ZippyRainbow opened 3 years ago

ZippyRainbow commented 3 years ago

I have an application working in the Android environment with MultiScan (Reader) working fine (Once: False)

But when I try the same function in iOS it can read the first scan and collect the data, but the operating system doesn't acknowledge the scan and is still waiting for a NFC device. If you press Cancel then you can restart and redo a scan.

In iOS, for Single Scan mode it works fine, but I fine that I can only re-read the next card after waiting for around 4 seconds for the NFC to be freed up before I can scan again.

I have tried this on multiple iOS devices and multi versions of flutter, all with the same result.

I am planning on looking into the NfcInFlutterPlugin.m file to see if I can work out where it is going wrong myself. Not something I have done before but I will see how I go.

ZippyRainbow commented 3 years ago

Okay, I worked out the issue, I started back with the sample Core NFC code from Apple.

For the iOS Multiscan to work (eg once:false, aka invalidateAfterFirstRead:false) you need to use the method readerSession(_:didDetectNDEFs:) https://developer.apple.com/documentation/corenfc/nfcndefreadersessiondelegate/2875568-readersession

But as per the documentation if you use readerSession(:didDetect:) then readerSession(:didDetectNDEFs:) doesn't fire.

So once I removed readerSession(_:didDetect:) it is now multiscanning in iOS without an issue.

I am now going to make some changes to this NfcInFlutterPlugin.m module to merge the changes into my project