Last active
December 27, 2018 14:26
-
-
Save myrickchow32/3dcdf74f9470868543e88aa8ff568faf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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