title: NFCTagReaderSession Swift unable to authenticate DESFire card
body: <p>I am trying to authenticate DESFire card using NFCTagReaderSession but unable to authenticate the card or proceed further to get information on the card using NFCTagReaderSession.</p>
  <p>Below is the Code that i have written:</p>
  <pre><code>func scan() {
          if !NFCReaderSession.readingAvailable {
              return
          }
          session = NFCTagReaderSession(pollingOption: .iso14443, delegate: self)
          session?.alertMessage = &quot;Hold your iPhone near the item to learn more about it.&quot;
          session?.begin()
      }
  </code></pre>
  <pre><code>func tagReaderSession(_ session: NFCTagReaderSession, didDetect tags: [NFCTag]) {
          guard let tag = tags.first else { return }
          session.connect(to: tag) { error in
              if error != nil {
                  session.invalidate(errorMessage: &quot;Connection error. Please try again.&quot;)
                  return
              }
              if case let NFCTag.iso7816(tag) = tags.first! {
                  print(&quot;Found NFC TAG&quot;)
              }
              if case let NFCTag.miFare(tag) = tags.first! {
                  session.connect(to: tags.first!) { (error: Error?) in
                      let apdu = NFCISO7816APDU(data: Data([0x35,0x6A,0x00,0x00,0x00]))
                      tag.sendMiFareCommand(commandPacket: Data([0x90,0x6A,0x00,0x00,0x00]), completionHandler: { data, error in
                          print(data)
                          let tagUIDData = data
                          var byteData: [UInt8] = []
                          tagUIDData.withUnsafeBytes { byteData.append(contentsOf: $0) }
                          var uidString = &quot;&quot;
                          for byte in byteData {
                              let decimalNumber = String(byte, radix: 16)
                              if (Int(decimalNumber) ?? 0) &lt; 10 { // add leading zero
                                  uidString.append(&quot;0\(decimalNumber)&quot;)
                              } else {
                                  uidString.append(decimalNumber)
                              }
                          }
                          debugPrint(&quot;\(byteData) converted to Tag UID: \(uidString)&quot;)
                      })
                      
                      tag.sendMiFareISO7816Command(apdu!) { (apduData, sw1, sw2, error) in
                          let tagUIDData = apduData.data// tag.identifier
                          
                          var byteData: [UInt8] = []
                          tagUIDData.withUnsafeBytes { byteData.append(contentsOf: $0) }
                          var uidString = &quot;&quot;
                          for byte in byteData {
                              let decimalNumber = String(byte, radix: 16)
                              if (Int(decimalNumber) ?? 0) &lt; 10 { // add leading zero
                                  uidString.append(&quot;0\(decimalNumber)&quot;)
                              } else {
                                  uidString.append(decimalNumber)
                              }
                          }
                          debugPrint(&quot;\(byteData) converted to Tag UID: \(uidString)&quot;)
                          print(apduData)
                      }
                      
                  }
              }
          }
          
      }
  </code></pre>
  <p>Using the above code i am getting basic details of the card, but not sure how to authenticate the card using AES. I am fairly new to NFC domain.</p>