NTAG213 NFC Tag reader in swift IOS using CORE NFC

427 views Asked by At

I am working on IOS application to read NTAG213 using CORE NFC and also used the sample application Used this link below https://developer.apple.com/documentation/corenfc/building_an_nfc_tag-reader_app I am not able to scan ntag213 tags. I am not able to find this issue . I am attaching the code here please let me know if I am doing anything wrong or I need to modify something to make it work scanning Ntag213.

I modified MessageTableViewController.swift file.

 func readerSession(_ session: NFCNDEFReaderSession, didDetect tags: [NFCNDEFTag]) {
        guard let tag = tags.first else {
            session.alertMessage = "No tag found."
            session.invalidate()
            return
        }
        
        session.connect(to: tag) { error in
            if let error = error {
                session.alertMessage = "Unable to connect to tag. Error: \(error.localizedDescription)"
                session.invalidate()
                return
            }
            
            tag.queryNDEFStatus { ndefStatus, capacity, error in
                if ndefStatus == .notSupported {
                    session.alertMessage = "Tag is not NDEF compliant."
                    session.invalidate()
                    return
                } else if let error = error {
                    session.alertMessage = "Unable to query NDEF status of tag. Error: \(error.localizedDescription)"
                    session.invalidate()
                    return
                }
                
                tag.readNDEF { message, error in
                    if let error = error {
                        session.alertMessage = "Fail to read NDEF from tag. Error: \(error.localizedDescription)"
                    } else if let message = message {
                        DispatchQueue.main.async {
                            // Process detected NFCNDEFMessage objects.
                            self.detectedMessages.append(message)
                            self.tableView.reloadData()
                            session.alertMessage = "Scanning successful!"
                        }
                    } else {
                        session.alertMessage = "No NDEF message found."
                    }
                    
                    session.invalidate()
                }
            }
        }
    }

0

There are 0 answers