Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to do "batch reads" on iOS? #461

Open
mpdude opened this issue Jan 3, 2022 · 2 comments
Open

How to do "batch reads" on iOS? #461

mpdude opened this issue Jan 3, 2022 · 2 comments

Comments

@mpdude
Copy link

mpdude commented Jan 3, 2022

Hello everyone,

I hope this question is not off-topic here and I must admit that I am not used to async/await thinking in JS (not my primary language).

I'd like to to a "batch read" of NFC tags on iOS. That is, after a tag has been successfully read, immediately start the next nfc.scanTag() session, until there is an error (including user aborts).

What I have been trying looks like this:

    function scanTags() {
        nfc.scanTag().then(
            function (tag) {
                if (tag.id) {
                    // do something with tag data
                    scanTags();
                }
            },
            function (err) {
                console.log(err);
            }
        );
    }

This does, however, not work. Here's what happens:

...
2022-01-03 09:51:23.584403+0100 MyApp[41717:9815571] tagReaderSessionDidBecomeActive
2022-01-03 09:51:24.962208+0100 MyApp[41717:9815571] tagReaderSession didDetectTags
2022-01-03 09:51:24.962460+0100 MyApp[41717:9815571] getTagInfo: NFCTagTypeMiFare with uid {length = 7, bytes = 0x04447582636b80}
2022-01-03 09:51:25.016302+0100 MyApp[41717:9815571] (null)
2022-01-03 09:51:25.016602+0100 MyApp[41717:9815571] [CoreNFC] 00000002 812c02d0 -[NFCTagReaderSession setAlertMessage:]:90  (null)
2022-01-03 09:51:25.016675+0100 MyApp[41717:9815571] fireNdefEvent
2022-01-03 09:51:25.016733+0100 MyApp[41717:9815571] Sending NFC data via sessionCallbackId
... my processing ...
... my code calling scanTags() again...
2022-01-03 09:51:25.025580+0100 MyApp[41717:9815571] scanTag
2022-01-03 09:51:25.025628+0100 MyApp[41717:9815571] shouldUseTagReaderSession 1
2022-01-03 09:51:25.025671+0100 MyApp[41717:9815571] callbackOnSessionStart 0
2022-01-03 09:51:25.025708+0100 MyApp[41717:9815571] returnTagInCallback 1
2022-01-03 09:51:25.025746+0100 MyApp[41717:9815571] returnTagInEvent 0
2022-01-03 09:51:25.025786+0100 MyApp[41717:9815571] Using NFCTagReaderSession
2022-01-03 09:51:27.874606+0100 MyApp[41717:9815571] tagReaderSession ended
2022-01-03 09:51:27.874779+0100 MyApp[41717:9815571] sendError: Session invalidated by user
2022-01-03 09:51:27.878658+0100 MyApp[41717:9815571] Session invalidated by user
2022-01-03 09:51:27.878865+0100 MyApp[41717:9815571] tagReaderSession ended
2022-01-03 09:51:27.878933+0100 MyApp[41717:9815571] sendError: System resource unavailable

To me it looks as if the tagReaderSession is still active handling the first tag (invoking my callback function), and I cannot enter another session from there.

This seems very understandable to me – the question, however, is: What is the right pattern/paradigm to solve this?

I could probably do something with timeouts and invoke scanTags() again one or two seconds after my callback has been invoked, but that seems rather clumsy.

I'd appreciate any tips or starting pointers. Thanks!

@justin-augustine-atlascopco

Hi, I am facing a similar problem. Were you able to resolve this issue?

@mpdude
Copy link
Author

mpdude commented May 12, 2023

In fact, the time-out based solution described above as a workaround

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

No branches or pull requests

2 participants