Skip to content

Latest commit

 

History

History
29 lines (20 loc) · 1.29 KB

715.md

File metadata and controls

29 lines (20 loc) · 1.29 KB
contributors
zntfdr

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.