I have this class to implement the scanner with NFC in my app. I have seen different tutorials and many people use this class. The error that it returns:
Type 'DniNFCViewController' does not conform to protocol 'NFCNDEFReaderSessionDelegate'
This error suggest me to add new methods (in my case readerSession) but they are already implemented. However, I have implemented this class in a new project and it works correctly.
//
// DniNFCViewController.swift
// SSLSignature
//
// Created by Ismael Márquez on 20/2/24.
// Copyright © 2024 aralink. All rights reserved.
//
import UIKit
import CoreNFC
class DniNFCViewController: UIViewController, NFCNDEFReaderSessionDelegate {
var nfcSession: NFCNDEFReaderSession?
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
@IBAction func startNFCSession(_ sender: Any) {
nfcSession = NFCNDEFReaderSession(delegate: self, queue: nil, invalidateAfterFirstRead: false)
nfcSession?.begin()
}
// MARK: - NFCNDEFReaderSessionDelegate
func readerSession(_ session: NFCNDEFReaderSession, didInvalidateWithError error: Error) {
print("Session invalidated with error: \(error.localizedDescription)")
}
func readerSession(_ session: NFCNDEFReaderSession, didDetectNDEFs messages: [NFCNDEFMessage]) {
// Handle NFC tag detection here
for message in messages {
for record in message.records {
// Process NDEF records
// This is where you would handle the data read from the NFC tag
print("Record payload: \(record.payload)")
}
}
}
}
how to resolve the problem and why this error happens?