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

Cancel iOS dialog: dialog won't come up anymore #36

Closed maganap closed 4 years ago

maganap commented 4 years ago

Hello!

I'm working with one time reading in iOS, as in: NFC.readNDEF(once: true, throwOnUserCancel: true);

Problem: When reading starts, the iOS native NFC dialog comes up. If the user cancels and requests reading again, the dialog won't come up anymore.

More info:

Tested on a real device, iPhone X iOS 13.3.1

Any ideas what the cause of this problem could be? Thanks in advance!

semlette commented 4 years ago

Have you tried the newly released version 2.0.4? It should have fixed this issue.

sspogra commented 4 years ago

Same issue.

martyfuhry commented 4 years ago

One of my users is reporting this issue in my app, as well, on an iPhone 11. I'm unable to reproduce on my iPhone 8. Haven't tried my other devices.

Says it happens when he cancels out, though it's hard to reproduce. It locks up iOS's NFC handler completely, and you can't get the NFC scan dialog to show up in any app until a complete device restart.

James-A-White commented 4 years ago

I'm having a similar problem. To reproduce on iOS:

  1. Start scanning, scan first tag, everything works as expected
  2. Start scanning, cancel scan, everything works as expected
  3. Start scanning, NFC dialog comes up but will not recognize tags. Cancelling works fine.
  4. Start scanning, NFC dialog comes up, don't cancel but wait for the dialog to timeout. After a period of time (around 5 seconds), the successful scan dialog comes up (with the checkmark) then goes away, but the listener is not triggered.

Any help would be greatly appreciated!

Thx!

=====

Update: the error seems a bit non-deterministic. Sometimes it works, sometimes it doesn't. I'm trying to figure out if it is a timing issue (e.g. if you cancel a stream too quickly, it fouls up the NFC processing pipeline?) In its current state, I'm not sure I could deploy an app in production given the erratic nature of this. Again, any help to resolve would be greatly appreciated!

=====

Another update: After cancelling the iOS dialog, the next time I try to start a reading session, an exception is immediately thrown, "Bad State: no element", which is typically associated with a .where clause in dart that results in zero items selected.

semlette commented 4 years ago

I have opened PR #39 which could fix this issue.

It definitely fixes not being able to scan a tag after manually closing the iOS popup or letting it timeout.

I would like to ask all of you to clone the code and do your best to mess with CoreNFC and see if it ever stops working.

Also if you any of you could tell me if you're able to scan more than one tag in the same session. I could never get it to scan more than one tag before timing out, and I don't know if it's a bug in nfc_in_flutter or CoreNFC because the CoreNFC documentation is, well.. not great

If you would like to use the code from the PR in your apps, you can set the nfc_in_flutter version in pubspec.yaml to the PR ref like so:

dependencies:
  nfc_in_flutter:
    git:
      url: git://github.com/semlette/nfc_in_flutter.git
      ref: simplify-error-handling-plus-fix
James-A-White commented 4 years ago

Will get to it this afternoon! Thanks! Jw

James-A-White commented 4 years ago

HUGE improvement! Still need to run through a more full suite of tests, but early indications look GREAT!

James-A-White commented 4 years ago

It looks like reading works great, but the fix for reading tags seems to have triggered a regression in the ability to write tags. Before, I was able to write and now unable to do so. If you need any data from me on this, please let me know. Thx! J

semlette commented 4 years ago

I've spent most of the day building an app for testing nfc_in_flutter, and I've just begun adding tests for writing, so I've just had a look at this.

I am still able to write using the writeNDEF() function, but it's definitely not working as intended. When writing using writeNDEF(), it triggers the NSLog on line 76 in NfcInFlutterPlugin.,m. Adding another NSLog to log the error (can't believe I didn't add that in the first place) reveals that the error is "Session invalidated by user". I wonder what's causing this. Continuing to investigate.

semlette commented 4 years ago

@James-A-White could you perhaps describe in better detail how the writing doesn't work for you? Android, iOS? Any platform-level logs from Android Studio or Xcode? Exceptions in Flutter?

I also now understand the behaviour in my comment above. I may have been a little too fast on the trigger. The error comes from invalidating the session because the Flutter-side stream is complete - because writeNDEF() is.

It's believe it's the expected behaviour.

James-A-White commented 4 years ago

I've pulled your latest code and am trying to get writing to work. On the positive side, the reading of tags is much more reliable now, even after cancelling. I think you can close this issue and we can move this discussion to issue #38.

semlette commented 4 years ago

I merged the PR because it seemed to fix this issue, but i am reluctant to release it, if it did indeed create a new bug related to writing.

Discussion on the potential new bug shall continue in #38

cmarfil commented 3 years ago

Hi, i still have this problem on iphone 7, even applying the branch, is it solved if I put throwOnUserCancel to false, but in that case I don't know when the user has canceled, is it supposed to be solved? thanks.

adham-ashraf77 commented 3 years ago

same issue here also.