ios – NFC Tag Reader Session HCE ISO 7816 tag

0
18
ios – NFC Tag Reader Session HCE ISO 7816 tag


I am attempting to learn an emulated HCE tag from one other software, however I all the time get the identical error within the sendCommand response:

-[NFCTagReaderSession _connectTag:error:]:744 Error Area=NFCError Code=2 "Lacking required entitlement" UserInfo={NSLocalizedDescription=Lacking required entitlement} ERROR: Tag is just not linked

That is my entitlements file:


    aps-environment
    improvement
    com.apple.developer.nfc.readersession.codecs
    
        TAG
        NDEF
    

That is my data.plist:





        UIBackgroundModes
        
            remote-notification
        
        com.apple.developer.nfc.readersession.iso7816.select-identifiers
        
            F00102030405
        

That is my code:

func startNFCSession() {
let pollingOptions: NFCTagReaderSession.PollingOption = [.iso14443]
nfcSession = NFCTagReaderSession(pollingOption: pollingOptions, delegate: self, queue: nil)
nfcSession?.alertMessage = NSLocalizedString("Maintain the gadget near scan the ticket.", remark: "")
nfcSession?.start()
}

func tagReaderSession(_ session: NFCTagReaderSession, didDetect tags: [NFCTag]) {
        
        if tags.depend > 1 {
            session.alertMessage = NSLocalizedString("A number of tags detected. Attempt once more.", remark: "")
            session.restartPolling()
            return
        }
    
        guard let firstTag = tags.first else {
            session.invalidate(errorMessage: NSLocalizedString("No tags discovered", remark: ""))
            return
        }
        
        guard case let .iso7816(iso7816Tag) = firstTag else {
            session.invalidate(errorMessage: NSLocalizedString("Incompatible tag", remark: ""))
            return
        }
        
        session.join(to: firstTag) { (error: Error?) in
            if let error = error {
                session.invalidate(errorMessage: String(format: NSLocalizedString("Connection error: %@", remark: ""), error.localizedDescription))
                return
            }
    
            let apduCommand = NFCISO7816APDU(
                instructionClass: 0x00,
                instructionCode: 0xA4,
                p1Parameter: 0x04,
                p2Parameter: 0x00,
                knowledge: Knowledge([0xF0, 0x01, 0x02, 0x03, 0x04, 0x05]),
                expectedResponseLength: -1
            )
            iso7816Tag.sendCommand(apdu: apduCommand) { (responseData, sw1, sw2, error) in
                if let error = error {
                    print("ERROR: (error.localizedDescription)")
                    session.invalidate(errorMessage: String(format: NSLocalizedString("Error sending APDU: %@", remark: ""), error.localizedDescription))
                } else {
                    self.handleResponse(session: session, responseData: responseData, sw1: sw1, sw2: sw2)
                }
            }
        }
    
    }

LEAVE A REPLY

Please enter your comment!
Please enter your name here