Search code examples
iosnfccore-nfc

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


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


Solution

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