Skip to content

Instantly share code, notes, and snippets.

@myrickchow32
Last active December 27, 2018 14:25
Show Gist options
  • Save myrickchow32/0049aa339e97355ba9ba769cd516ad19 to your computer and use it in GitHub Desktop.
Save myrickchow32/0049aa339e97355ba9ba769cd516ad19 to your computer and use it in GitHub Desktop.
// invalidateAfterFirstRead = false
var nfcSession = NFCNDEFReaderSession.init(delegate: self, queue: nil, invalidateAfterFirstRead: false)
nfcSession.begin()
extension ViewController: NFCNDEFReaderSessionDelegate {
func readerSession(_ session: NFCNDEFReaderSession, didDetectNDEFs messages: [NFCNDEFMessage]) {
// Handling of [NFCNDEFMessage] and return the result String
var result = ...
// Step 8: didDetectNDEFs callback is run in background thread. All UI updates must be handled carefully.
DispatchQueue.main.asyncAfter(deadline: .now() + 1) { [weak self] in
self?.nfcSession.invalidate()
self?.showAlert("Scanned NFC tag info: " + result) // Simply show an UIAlertController with message
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment