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
120 stars 119 forks source link

nfc_in_flutter in ios #80

Open alrashidi7 opened 3 years ago

alrashidi7 commented 3 years ago

hello every one, I don't have much experience with nfc at all I encountered a problem while using this plugin in ios , which is the process of executing the function inside read tag or write tag not execute it until I clicked the cancel button in NFC-core dialog in ios 14 can any one help me

ZippyRainbow commented 3 years ago

Hi @alrashidi7, I think this is a unknown issue in regards to nic_in_flutter which was identified in the ReadMe Doc. The phone locks up when the NFC is active in iOS. If you print the activity on the function you should see that the data is being read.

Maybe related, I found that the Multiscan option doesn't active a "tick" in iOS when an NFC is scanned, but works fine with a single scan. I am planning on bug testing this further as I need the MultiScan to work, as the Single Scan is too slow for my application.

adham-ashraf77 commented 3 years ago

I have an issue in reading NFC in ios too the function runs one time only if I want to show dialog between each time must wait 5 seconds.

ZippyRainbow commented 3 years ago

@adham-ashraf77 , See my Issue request (86) on MultiScaning on IOS. I found I needed to remove readerSession(_:didDetect:) to get the multiscan to work, then I can scan quickly. But it still times out every 60 seconds and needs 4 seconds to restart.. but I think that is just IOS.

https://github.com/semlette/nfc_in_flutter/issues/86

adham-ashraf77 commented 3 years ago

@ZippyRainbow can you provide a pull request for this fix please with null safety.

adham-ashraf77 commented 3 years ago

@ZippyRainbow i really need that fix for ios please

ZippyRainbow commented 3 years ago

@adham-ashraf77 I am a bit of a novice with GitHub, I tried to create a pull request but couldn't work out how to add one, it seemed like the option was greyed out for my access. Maybe I need a paid Github account?

adham-ashraf77 commented 3 years ago

@ZippyRainbow can you provide me what code you change or send me the file changes at adhamashraf51@gmail.com and you can use your own fork form this repo and upload your commit and changes.

ZippyRainbow commented 3 years ago

@adham-ashraf77 I assume you have read my Issue #86 I just removed the readerSession(_:didDetect:) subroutine from the nfc_in_flutter/ios/Classes/NfcInFlutterPlugin.m file, lines 470 to 507.

Starting from.

(void)readerSession:(NFCNDEFReaderSession *)session didDetectTags:(NSArray<__kindof id<NFCNDEFTag>> *)tags API_AVAILABLE(ios(13.0)) {

This will force the NDEF Tag detect to activate for MultiScan:

(void)readerSession:(nonnull NFCNDEFReaderSession *)session didDetectNDEFs:(nonnull NSArray *)messages API_AVAILABLE(ios(11.0)) {
adham-ashraf77 commented 3 years ago

This will force the NDEF Tag detect to activate for MultiScan:

(void)readerSession:(nonnull NFCNDEFReaderSession )session didDetectNDEFs:(nonnull NSArray )messages API_AVAILABLE(ios(11.0)) {

where do I add this code?

ZippyRainbow commented 3 years ago

Hey @adham-ashraf77 Nothing needs adding. Just need to remove out lines 470 to 507 in nfc_in_flutter/ios/Classes/NfcInFlutterPlugin.m file.

Once there is no "didDetectTags" function it will use the "didDetectNDEFs" function on IOS Multiscan instead. This is the problem. with "didDetectTags" in the code, this is being used instead of "didDetectNDEFs".. which we need it to use..

Details of this is on the apple development page, under the Discussion Notes. https://developer.apple.com/documentation/corenfc/nfcndefreadersessiondelegate/2875568-readersession

adham-ashraf77 commented 3 years ago
Screen Shot 2021-05-27 at 8 50 49 AM

i tried to remove it and no multiscan

adham-ashraf77 commented 3 years ago

But it still times out every 60 seconds and needs 4 seconds to restart.. but I think that is just IOS. it shows it open after 60 seconds and still a problem there is an app called popl handle the NFC error.

ZippyRainbow commented 3 years ago

@adham-ashraf77 Are you using the code something like this in flutter? With once: false?

 _stream = NFC
          .readNDEF(alertMessage: "Scan your Card to record your time.", readerMode: NFCDispatchReaderMode(), throwOnUserCancel: false, once: false)
          .listen((NDEFMessage message) {
        if (message.isEmpty) {
          print("Read empty NDEF message");
ZippyRainbow commented 3 years ago

But it still times out every 60 seconds and needs 4 seconds to restart.. but I think that is just IOS. it shows it open after 60 seconds and still a problem there is an app called popl handle the NFC error.

Yeap, that is as good as I can get it to work with IOS. The IOS still times out after 60 seconds.

Without deleting the "didDetectTags" it wouldn't work at all with multiscan and ticking to show it was reading.

adham-ashraf77 commented 3 years ago

@adham-ashraf77 Are you using the code something like this in flutter? With once: false?

 _stream = NFC
          .readNDEF(alertMessage: "Scan your Card to record your time.", readerMode: NFCDispatchReaderMode(), throwOnUserCancel: false, once: false)
          .listen((NDEFMessage message) {
        if (message.isEmpty) {
          print("Read empty NDEF message");

once true i use NDEFMessage message = await NFC.readNDEF(once: true).first;

ZippyRainbow commented 3 years ago

@adham-ashraf77 Are you using the code something like this in flutter? With once: false?

 _stream = NFC
          .readNDEF(alertMessage: "Scan your Card to record your time.", readerMode: NFCDispatchReaderMode(), throwOnUserCancel: false, once: false)
          .listen((NDEFMessage message) {
        if (message.isEmpty) {
          print("Read empty NDEF message");

once true i use NDEFMessage message = await NFC.readNDEF(once: true).first;

If you want to scan quickly, you need to use multiscan, else you can only scan once every 4 seconds.. I am pretty sure it is an Apple (iOS) thing.. as it needs to close and reopen the NFC Core.

adham-ashraf77 commented 3 years ago

and how to use multiscan?

ZippyRainbow commented 3 years ago

Once: false

adham-ashraf77 commented 3 years ago

https://drive.google.com/file/d/1GWuKj57LggIZkdEGhRcXBh0krU1vH_PD/view?usp=sharing here is a video from popl app it handles the cancellation.

ZippyRainbow commented 3 years ago

@adham-ashraf77 if you are not getting the ios "Ready to Scan" at all you might need look at the sample code again to see what you are missing. I assume your application is the one on the left in the video you posted.

adham-ashraf77 commented 3 years ago

@adham-ashraf77 if you are not getting the ios "Ready to Scan" at all you might need to look at the sample code again to see what you are missing. I assume your application is the one on the left in the video you posted.

get it the first time but if I click again without wait 4 seconds it will not appear again until we restart the app.

adham-ashraf77 commented 3 years ago

@ZippyRainbow i just wanna to be like popl

adham-ashraf77 commented 3 years ago

@ZippyRainbow I figure out something that will not appear in app I turn NFC scan from IOS system is open from the app the scan NFC restarts the NFC app.

ZippyRainbow commented 3 years ago

@ZippyRainbow i just wanna to be like popl

Yeap, would be good. I don't know that much about the ios nfc to bug test much as I don't own a mac