Core NFC - can read a NFC tag - now I need payload data

Hi - using code that is out there I have managed to create a skeleton app that will read in a NFC tag on the iPhone 7+ and display the details in the debugger using this code:



func readerSession(_ session: NFCNDEFReaderSession, didDetectNDEFs messages: [NFCNDEFMessage]) {

print("New NFC Tag detected:")

for message in messages {

for record in message.records {

print("Type name: \(record.typeNameFormat)")

print("Payload size: \(record.payload)")

print("Type size: \(record.type)")

print("Identifier: \(record.identifier)")

}

}

Very happy with that!


The data is correct, but I want to print the payload data and cant figure out how to get to it and the documentation seems non existent. Looking around the groups most examples seem to go as far as the above in terms of the size of the payload rather than the value.


I found nfcndefpayload


https://developer.apple.com/documentation/corenfc/nfcndefpayload


Any help of a code example to kick start me as a newbie Swift developer that would be very helpful.

Hi - I found your source code for the example app and found my answer!



if let dataMessage = String(data: payload.payload, encoding:.utf8) {

cell.textLabel?.text = "Data recieved: " + dataMessage

}

Just in case you are having issues - we managed to get this working and created a version that automatically launches the URL on the tag to the browser :


https://vimeo.com/221143249


We have found issue on Beta IOS 11 where after so many taps it stops scanning and have to reboot the phone, but will report that seperatly when we get some facts around it... so if you get an issue where your NFC tags are not being picked up a reboot migh tbe worth doing...

It is possible to read protected NFC tags in iOS?


I searched around NFC NDEF protocols in Apple documentation but there is no functions that require a challenge/handshake for NFC tags. Is there a way to interact with these types of NFC tags?

Core NFC - can read a NFC tag - now I need payload data
 
 
Q