Skip to content
This repository has been archived by the owner on Jun 23, 2024. It is now read-only.

nfc_in_flutter in ios #80

Open
alrashidi7 opened this issue Mar 4, 2021 · 24 comments
Open

nfc_in_flutter in ios #80

alrashidi7 opened this issue Mar 4, 2021 · 24 comments

Comments

@alrashidi7
Copy link

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
Copy link

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
Copy link

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
Copy link

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

#86

@adham-ashraf77
Copy link

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

@adham-ashraf77
Copy link

@ZippyRainbow i really need that fix for ios please

@ZippyRainbow
Copy link

@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
Copy link

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

@ZippyRainbow
Copy link

ZippyRainbow commented May 26, 2021

@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
Copy link

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
Copy link

ZippyRainbow commented May 27, 2021

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
Copy link

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

i tried to remove it and no multiscan

@adham-ashraf77
Copy link

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
Copy link

ZippyRainbow commented May 27, 2021

@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
Copy link

ZippyRainbow commented May 27, 2021

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
Copy link

@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
Copy link

@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
Copy link

and how to use multiscan?

@ZippyRainbow
Copy link

Once: false

@adham-ashraf77
Copy link

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

@ZippyRainbow
Copy link

ZippyRainbow commented May 27, 2021

@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
Copy link

@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
Copy link

@ZippyRainbow i just wanna to be like popl

@adham-ashraf77
Copy link

@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
Copy link

@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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants