How does one read/parse the NDEF Message from CoreNFC?

I have a bunch of tags that are URL tags that have the content "http://WEBSITE.com". Let's say WEBSITE is youtube so http://youtube.com. When I scan them on Android etc, it keeps the http or https.


I'm trying to scan these same tags using the Core NFC framework. I scan them and I get a bunch of bytes that I convert using NSSString initWithData with UTF8 Encoding. I get back \^Cyoutube.com. I want to get http://youtube.com.


How can I interept the payload to get what I need? If I'm to assume the http in front of the string, how am I supposed to know if it is http or https or even ftp?

hi dberroa,

you have to parse your NDEF paylaod accordingly. I have done the following, and it works fine (I don't handle here every scheme for URI) :

But take care that URI NDEF is not native into iOS. Once extracted URI, you have to call your browser with URI

hoe it helps


let dataPayloadRecordHex = nfcTag.payload.toHexString()

let dataPayloadRecord = String(data: nfcTag.payload,encoding:.utf8)

let dataTypeRecord = String(data: nfcTag.type,encoding:.utf8)

let dataIdentifierRecord = String(data: nfcTag.identifier,encoding:.utf8)

var messageString = ""


switch (nfcTag.typeNameFormat){

case .nfcWellKnown:

/

if (nfcTag.type.hashValue == 0x55){

/

let schemeURI = nfcTag.payload[0]

switch schemeURI {

case 0:

uriSchemeString = ""

break

case 1:

uriSchemeString="http:/

break

case 2:

uriSchemeString="https:/

break

default:

uriSchemeString="http:/

}

messageString.append("URI = "+uriSchemeString+dataPayloadRecord!+"\n")

How does one read/parse the NDEF Message from CoreNFC?
 
 
Q