Is it possible to hide iOS system alert for NFC reading session
Asked Answered
K

1

10

When you successfully finish an NFC reading session you'll see something like that:

Successfully finished NFC session

This will overlay the currently presented ViewController for about 3 seconds. The fun part is that this behaviour is inconsistent since this window will disappear immediately if the reading session finish very fast.

It means that I cannot be sure about how long will this overlay stay for sure which is bad for our app's UX design.

The question is simple: is there a way to force this overlay to disappear or at least to handle the event of when it disappears (not when the NFC session if finished)?

Karlee answered 22/5, 2018 at 9:57 Comment(4)
Can you show some code? What you are describing sounds like you aren't using the main queueFiddling
@Fiddling it's a part of a commercial product so I guess that I can't. I'm sure that completion is executed on the main thread since it's handled by RxSwfit .observeOn(MainScheduler()). Moreover, the behaviour is consistent as I mentioned: if the reading session is finished very fast (in < 0.5 sec) this system alert is dismissed immediately. Any time the session is longer - this alert is presented for about 3 seconds (always the same time, not different) before being dismissed.Karlee
What queue do you pass when you set up your NFCNDefReaderSession? Try this and see if you get the same behaviour; github.com/hansemannn/iOS11-NFC-ExampleFiddling
@Fiddling I don't add a custom queue for NFCNDefReaderSession so it chooses some background queue (not main) under the hood but I observe the results on the main queue.Karlee
K
17

I've found an interesting way to hide that window. 2 simple steps are required:

1) When initialising your reader session set the last parameter to false: NFCNDEFReaderSession(delegate: self, queue: nil, invalidateAfterFirstRead: false)

2) In the body of readerSession(_ session: NFCNDEFReaderSession, didDetectNDEFs messages: [NFCNDEFMessage]) your should call session.invalidate().

That's it. It will work as if you tapped Cancel/Done - the system window will disappear immediately.

Karlee answered 6/6, 2018 at 22:34 Comment(3)
Actually you might want delay session invalidation for about 0.5 seconds, so user will have a chance to see checkmark screenLegislator
This doesn't work. At least not on iOS 12. The dialoge remains for around a second no matter what. Basically breaks any useful application of NFC.Fee
Since you cannot control when this disappears, what is the best alternative? See my question here: #77208014Maiduguri

© 2022 - 2024 — McMap. All rights reserved.