nfc_in_flutter icon indicating copy to clipboard operation
nfc_in_flutter copied to clipboard

nfc_in_flutter in ios

Open alrashidi7 opened this issue 4 years ago • 24 comments

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

alrashidi7 avatar Mar 04 '21 13:03 alrashidi7

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.

ZippyRainbow avatar Mar 31 '21 09:03 ZippyRainbow

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.

adham-ashraf77 avatar May 26 '21 13:05 adham-ashraf77

@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

ZippyRainbow avatar May 26 '21 22:05 ZippyRainbow

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

adham-ashraf77 avatar May 26 '21 22:05 adham-ashraf77

@ZippyRainbow i really need that fix for ios please

adham-ashraf77 avatar May 26 '21 23:05 adham-ashraf77

@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?

ZippyRainbow avatar May 26 '21 23:05 ZippyRainbow

@ZippyRainbow can you provide me what code you change or send me the file changes at [email protected] and you can use your own fork form this repo and upload your commit and changes.

adham-ashraf77 avatar May 26 '21 23:05 adham-ashraf77

@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)) {

ZippyRainbow avatar May 26 '21 23:05 ZippyRainbow

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?

adham-ashraf77 avatar May 27 '21 06:05 adham-ashraf77

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

ZippyRainbow avatar May 27 '21 06:05 ZippyRainbow

Screen Shot 2021-05-27 at 8 50 49 AM

i tried to remove it and no multiscan

adham-ashraf77 avatar May 27 '21 06:05 adham-ashraf77

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.

adham-ashraf77 avatar May 27 '21 07:05 adham-ashraf77

@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 avatar May 27 '21 07:05 ZippyRainbow

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.

ZippyRainbow avatar May 27 '21 07:05 ZippyRainbow

@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;

adham-ashraf77 avatar May 27 '21 07:05 adham-ashraf77

@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.

ZippyRainbow avatar May 27 '21 07:05 ZippyRainbow

and how to use multiscan?

adham-ashraf77 avatar May 27 '21 07:05 adham-ashraf77

Once: false

ZippyRainbow avatar May 27 '21 07:05 ZippyRainbow

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

adham-ashraf77 avatar May 27 '21 08:05 adham-ashraf77

@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.

ZippyRainbow avatar May 27 '21 09:05 ZippyRainbow

@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 avatar May 27 '21 09:05 adham-ashraf77

@ZippyRainbow i just wanna to be like popl

adham-ashraf77 avatar May 27 '21 09:05 adham-ashraf77

@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.

adham-ashraf77 avatar May 27 '21 09:05 adham-ashraf77

@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

ZippyRainbow avatar May 27 '21 10:05 ZippyRainbow