Skip to content

Instantly share code, notes, and snippets.

@myrickchow32
Last active December 27, 2018 14:26
Show Gist options
  • Save myrickchow32/3dcdf74f9470868543e88aa8ff568faf to your computer and use it in GitHub Desktop.
Save myrickchow32/3dcdf74f9470868543e88aa8ff568faf to your computer and use it in GitHub Desktop.
// invalidateAfterFirstRead = true
var nfcSession = NFCNDEFReaderSession.init(delegate: self, queue: nil, invalidateAfterFirstRead: true)
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.async { [weak self] in
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