swift – Learn uid from all NFC playing cards in ios

0
33
swift – Learn uid from all NFC playing cards in ios


I am attempting to retrieve the UID from an NFC card in order that customers can learn it and assign it to a job within the database. Nonetheless, I am encountering just a few issues:

I’ve two NFC playing cards, however with the NFC Instruments app, I can solely learn one card, and solely in compatibility mode.

Appears that some NFC playing cards might not work properly with iOS, as each playing cards work accurately with Android. Is that this seemingly a {hardware} problem with iOS, or might the NFC playing cards be too outdated? There’s one other option to obtain this?

I additionally tried utilizing the answer from https://stackoverflow.com/questions/58285425/read-uid-from-nfc-mifare-tag-ios-13
, however I encountered the error “Kind ‘ViewController’ doesn’t conform to protocol ‘NFCTagReaderSessionDelegate'” and I am unable to get it to work.

Additionally downloaded a number of NFC apps to attempt to retrieve the UID, however or would not get detected or solely reads the worth I had written in 1 of the two playing cards (once more in android each obtained detected and return the uid).
working nfc
.

not working nfc

That is the swift code:

import UIKit
import CoreNFC

class ViewController: UIViewController, NFCTagReaderSessionDelegate {

    var nfcSession: NFCTagReaderSession?

    override func viewDidLoad() {
        tremendous.viewDidLoad()
    }

    @IBAction func startNFCScan(_ sender: UIButton) {
        guard NFCTagReaderSession.readingAvailable else {
            print("NFC no disponible en este dispositivo.")
            return
        }
        
        nfcSession = NFCTagReaderSession(pollingOption: .iso14443, delegate: self)
        nfcSession?.alertMessage = "Acerca una etiqueta NFC."
        nfcSession?.start()
    }

    func tagReaderSession(_ session: NFCTagReaderSession, didDetect tags: [NFCTag]) {
        let tag = tags.first!
        session.join(to: tag, completionHandler: { error in
            if case let .miFare(miFare) = tag {
                var byteData = [UInt8]()
                miFare.identifier.withUnsafeBytes { byteData.append(contentsOf: $0) }
                var uid = "0"
                byteData.forEach {
                    uid.append(String($0, radix: 16))
                }
                print("UID: (uid)")
            }
        })
    }

    func tagReaderSession(_ session: NFCTagReaderSession, didInvalidateWithError error: Error) {
        print("Error en la sesión NFC: (error.localizedDescription)")
    }

}

LEAVE A REPLY

Please enter your comment!
Please enter your name here