NFCTag
An object that represents an NFC tag object.
Declaration
enum NFCTagOverview
When an NFC reader session detects a tag, it returns an NFCTag object. Use this generic object to determine if the tag is available, and to retrieve an object of a specific tag type.
Listing 1. Getting a MIFARE Ultralight tag from an array of generic tags objects
func tagReaderSession(_ session: NFCTagReaderSession, didDetect tags: [NFCTag]) {
var tag: NFCTag? = nil
for nfcTag in tags {
// In this example you are searching for a MIFARE Ultralight tag (NFC Forum T2T tag platform).
if case let .miFare(mifareTag) = nfcTag {
if mifareTag.mifareFamily == .ultralight {
tag = nfcTag
break
}
}
}
if tag == nil {
session.invalidate(errorMessage: "No valid coupon found.")
return
}
session.connect(to: tag!) { (error: Error?) in
if error != nil {
session.invalidate(errorMessage: "Connection error. Please try again.")
return
}
self.readCouponCode(from: tag!)
}
}