How can apps display the result of an NFC read until the user chooses to dismiss?

180 Views Asked by At

When reading NFC tags, iOS shows an action sheet at the bottom of the screen. You can use this action sheet to display the process of the read, and also display the result.

A general problem is that the app developer and the user has very little control over this action sheet other than adjusting the alertMessage. You can't control how long it is displayed or precisely control when it disappears. I saw a related question here about hiding the NFC action sheet. I know I can't do that. So what is the alternative?

The code below tries to show the value read on this action sheet, but it disappears about 1 second after it is presented, which isn't long enough for the user to process the information displayed. As an alternative, I show the same information in a pop-up dialog using a UIAlertController so the user can see the value read of as long as necessary before choosing to dismiss it.

The specific problem is that the pop-up dialog shows up behind the action sheet for a full second and the whole process looks disjointed and awkward.

Is there a smoother way to display the result of a read that allows the user to continue to see the value read and control when it disappears? This is important for longer and more complex read values that take some time for the app user to read and intellectually process.

tag.readNDEF { message, error in
if let message = message {
  let textMessage = self.parsePayloads(payloads: message.records) ?? "(none)"
  session.alertMessage = "Field read: \(textMessage)"
  session.invalidate() 
  DispatchQueue.main.async {
   let alertView = UIAlertController(title: "Field Read", message: textMessage, preferredStyle: UIAlertController.Style.alert)
   alertView.addAction(UIAlertAction(title: "OK", style: .default))
   self.viewController?.present(alertView, animated: true)
  }}
}

enter image description here enter image description here

0

There are 0 best solutions below