title: How to parse NFC data of Type U
body: <p>I am trying to <code>parse</code> the payload from a formatted <code>NFC chip</code> but I am having a problem when it comes to <code>record.type == U</code></p>
  
  <p>I am using an Android phone with app <code>NXP writer</code>, to write my NFC chips.
  I get everything for <code>record.type == T</code>, but when I get <code>record.type == U</code>, I having some difficulties. </p>
  
  <p>The idea that I found online is, that converting the <code>data to hexString</code> and <code>checking the first 2 numbers</code>, then you could categorise the following categories that a URI can have.</p>
  
  <p><a href="https://stackoverflow.com/questions/44445159/ios-11-how-does-one-read-parse-the-ndef-message-from-corenfc?answertab=votes#tab-top">iOS 11 - How does one read/parse the NDEF Message from CoreNFC?</a></p>
  
  <p>examples:</p>
  
  <ol>
  <li>0x00 N/A. No prepending is done </li>
  <li>0x01 <a href="http://www" rel="nofollow noreferrer">http://www</a>.</li>
  <li>0x02 <a href="https://www" rel="nofollow noreferrer">https://www</a>.</li>
  <li>0x03 http://</li>
  <li>0x04 https://</li>
  <li>0x05 tel:</li>
  <li>0x06 mailto:</li>
  <li>0x07 <a href="ftp://anonymous:anonymous@" rel="nofollow noreferrer">ftp://anonymous:anonymous@</a></li>
  <li>0x08 <a href="ftp://ftp" rel="nofollow noreferrer">ftp://ftp</a>.</li>
  </ol>
  
  <p>etc</p>
  
  <p>hexString = "02676f6f676c652e636f6d"</p>
  
  <p>substring = "02"</p>
  
  <p>Then we have <code>https://www</code> and we add the String from the payload, and open safari (or what ever we want to do).</p>
  
  <p><code>The problem comes when I want to read a NFC Tag/chip that contains Tel, mailto, geo, sms so far.</code></p>
  
  <p><code>The code is 3 digits</code> 006 instead of 2 digits as I read online. And not only that, if I decide to have a geolocation, <code>I get 006 which is the same with mailto code</code>. Of course I can solve this problem with more code but since there are solutions that they check only those codes, is there something that I could do, or am I doing something wrong?</p>
  
  <p>Questions:</p>
  
  <ol>
  <li>Is there an issue with NXP writer and I am facing this problem?</li>
  <li>Does the NFC coding have been changed?</li>
  <li>Is my logic correct ?</li>
  </ol>
  
  <p>Here is my code:</p>
  
  <pre><code>    func readerSession(_ session: NFCNDEFReaderSession, didDetectNDEFs messages: [NFCNDEFMessage]) {
      session.invalidate()
  
  
      for message in messages{
  
          for record in message.records{
  
              guard record.payload.count &gt; 0 else {
                  print("Record payload doesn't contain any data in the memory")
                  session.invalidate()
                  return
              }
  
              guard let NFCTypeFromTag = String(data: record.type, encoding: .utf8) else{
                  print("Unable to detect the Type")
                  session.invalidate()
                  return
              }
  
              guard let nfcTypeInput = NFCType(rawValue: NFCTypeFromTag) else {
                  print("nfc enum problem")
                  session.invalidate()
                  return
              }
  
              switch nfcTypeInput{
              case .T:
                  guard let NFCStringFromPayload = String(data: record.payload.advanced(by: 3), encoding: .utf8) else {
                      return
                  }
                  NFCString = NFCStringFromPayload
              case .U:
                  guard let NFCStringFromPayload = String(data: record.payload, encoding: .utf8) else{
                      print("Error: Unable to convert record.payload to String")
                      return
                  }
  
                  let hexString = record.payload.hexEncodedString()
                  let indexEndFromHexString = hexString.index(hexString.startIndex, offsetBy: 2)
  
                  let substring = hexString[hexString.startIndex ..&lt; indexEndFromHexString]
  
                  print("NFCString : \(NFCStringFromPayload)")
                  print("HexString : \(hexString)")
                  print("Substring : \(substring)")
  
                  if substring == "00"{
                      let indexEndOfHexStringCase00 = hexString.index(hexString.startIndex, offsetBy: 3)
                      let substringCase00 = hexString[hexString.startIndex..&lt;indexEndOfHexStringCase00]
                      if substringCase00 == "005" {
                          print("Tel:")
                      }else if substringCase00 == "006"{
                          print("mailto:")
                      }else if substringCase00 == "007" {
                          print("sms")
                      }
                  }else if substring == "01"{
                      print("http://www")
                  }else if substring == "02"{
                      print("https://www")
                  }
  
                  NFCString = NFCStringFromPayload
  
             case .Sp:
                  break
              }
              NFCArray.append(NFCString!)
              tableView.reloadData()
              print("NFC String : \(NFCString)")
  
          }
      }
  </code></pre>
  
  <p>Apple has a terrible documentation on CoreNFC.</p>
  
  <p>Is there any similar solution that someone has implement.</p>
  
  <p>Thank you in advance.</p>