来自一个类似的问题(Cannot read the NFC chip of the ePassport using iOS13)我也尝试按照与另一个问题相同的方法使用 iOS13 读取 eID 上的信息,但我似乎无法获得之后的步骤扫描文档以工作。(例如使用 MRZ 代码创建 BAC 并相应地读取数据)
任何建议或更多信息?有人已经设法让这个工作了吗?非常感谢!
编辑:添加了当前工作代码以改进和澄清问题。
import UIKit
import CoreNFC
class ViewController: UIViewController, NFCTagReaderSessionDelegate {
var readerSession: NFCTagReaderSession?
func tagReaderSessionDidBecomeActive(_ session: NFCTagReaderSession) {
}
func tagReaderSession(_ session: NFCTagReaderSession, didInvalidateWithError error: Error) {
print(error)
}
func tagReaderSession(_ session: NFCTagReaderSession, didDetect tags: [NFCTag]) {
var ndefTag: NFCNDEFTag
switch tags.first! {
case let .iso7816(tag):
ndefTag = tag
default:
session.invalidate(errorMessage: "Card not valid")
return
}
session.connect(to: tags.first!) { (error: Error?) in
if error != nil {
session.invalidate(errorMessage: "Connection error. Please try again.")
return
}
let card: NFCISO7816Tag
card = ndefTag as! NFCISO7816Tag
print(card)
}
}
@IBAction func nfcButton(_ sender: Any) {
guard NFCNDEFReaderSession.readingAvailable else {
let alertController = UIAlertController(
title: "Scanning Not Supported",
message: "This device doesn't support scanning your identity document.",
preferredStyle: .alert
)
alertController.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
self.present(alertController, animated: true, completion: nil)
return
}
readerSession = NFCTagReaderSession(pollingOption: [.iso14443], delegate: self, queue: nil)
readerSession?.alertMessage = "Place the device on the identity document."
readerSession?.begin()
}
}