Core NFC Enhancements

Description: Learn how easy it is to add support for NFC in your app and take advantage of the newest capabilities such as NDEF writing and support for widely adopted native tag protocols.

With iOS 13 any iPhone from the iPhone 7 lineup and later can both read and write NDEF NFC Tags (NFC Data Exchange Format).

We need to declare in the entitlements which tags we want to be able to read (basically a prefix of the tag identifier).

To write NDEF tags, we use the NFCNDEFReaderSession and, after detecting the tag, we can read/write/lock it:

// New NFCNDEFReaderSessionDelegate method to receive NDEF tag objects 

optional func readerSession(_ session: NFCNDEFReaderSession, didDetect tags: [NFCNDEFTag])

// NDEF tag protocol 

var isAvailable: Bool { get } 
func queryNDEFStatus(completionHandler: @escaping (NFCNDEFStatus, Int, Error?) -> Void)
func readNDEF(completionHandler: @escaping (NFCNDEFMessage?, Error?) -> Void)
func writeNDEF(_ ndefMessage: NFCNDEFMessage, completionHandler: @escaping (Error?) -> Void)
func writeLock(completionHandler: @escaping (Error?) -> Void) 

The sessions come with sample code to read and write NFC tags.

Missing anything? Corrections? Contributions are welcome 😃


Written by

Federico Zanetello

Federico Zanetello

iOS Engineer with strong passion for Swift, minimalism, and design. When he’s not busy automating things, he can be found writing at FIVE STARS and/or playing with the latest shiny toys.