Reputation: 11
I'm working on handing over data through NFC on my iOS smartphone. So I installed the NFC Reader app on my Android phone and am testing it. An error occurs in transmitting data through APDU after finding out that the tag is ISO7816.
func tagReaderSession(_ session: NFCTagReaderSession, didDetect tags: [NFCTag]) {
guard let firstTag = tags.first else {
session.invalidate(errorMessage: "No tags found.")
return
}
session.connect(to: firstTag) { (error: Error?) in
if let error = error {
session.invalidate(errorMessage: "Failed to connect to tag: \(error.localizedDescription)")
return
}
switch firstTag {
case .miFare(let miFareTag):
self.writeIDToTag(tag: miFareTag, id: "YOUR_IDENTIFIER_STRING", session: session)
case .feliCa(let felicaTag):
NSLog("didDetect_felicaTag")
break
case .iso15693(let iso15693Tag):
NSLog("didDetect_iSO15693")
break
case .iso7816(let iso7816Tag):
NSLog("didDetect_iSO7816")
let data = "ABCDEFGHIJK".data(using: .utf8)
let apduCmd = NFCISO7816APDU(
instructionClass: 0x00,
instructionCode: 0xA4,
p1Parameter: 0x04,
p2Parameter: 0x00,
data: data!,
expectedResponseLength: 256
)
iso7816Tag.sendCommand(apdu: apduCmd) { responseData, sw1, sw2, error in
if let error = error {
session.invalidate(errorMessage: "Failed to send APDU command: \(error.localizedDescription)") `// Error: Missing required entitlement`
}
let statusWord = (sw1 << 8) + sw2
print("APDU Response Data: \(responseData), Status Word: \(statusWord)")
session.invalidate()
}
break
default:
session.invalidate(errorMessage: "Unsupported tag.")
}
}
}
I checked everything, why do I get an error?
Additionally, installing the NFC Scan app on iOS will cause this error. connection to service with pid 60 named com.apple.nfcd.service.corenfc: Exception caught during decoding of received selector didDetectExternalReaderWithNotification:, dropping incoming message. Exception: Exception while decoding argument 0 (#2 of invocation): Exception: decodeObjectForKey: class "NFFieldNotificationECP1_0" not loaded or does not exist
If anyone knows a solution to either of them please.
Upvotes: 0
Views: 44