SITHSManager
用于读取和解析瑞典 SITHS 身份智能卡基本内容的 iOS 辅助类,配合 Precise Biometrics 读卡器。
由 Appcorn AB 为 Svensk e-identitet 制作。
示例
要运行示例项目,首先克隆仓库,然后在 Example 目录中运行 pod install
。
SITHSManager
辅助类的基本使用是通过 state
和 stateClosure
属性完成的。
以下是一个简单的视图控制器示例,显示了读卡器的当前状态以及插入的任何 SITHS 卡
import UIKit
import SITHSManager
class ViewController: UIViewController {
@IBOutlet weak var stateLabel: UILabel! // Simple label on the view to show status
let sithsManager = SITHSManager() // Store a reference to the manager, so it's not released (causing notifications to stop)
override func viewDidLoad() {
super.viewDidLoad()
// Add a state change closure, the state can also be read from the `sithsManager.state` property directly
sithsManager.stateClosure = { [weak self] state in
guard let stateLabel = self?.stateLabel else {
return
}
// Switch for the different states
switch state {
case .unknown:
stateLabel.textColor = .black
stateLabel.text = "Unknown"
case .readingFromCard:
stateLabel.textColor = .black
stateLabel.text = "Reading From Card..."
case .error(let error):
stateLabel.textColor = .red
stateLabel.text = "Error \(error)"
case .readerDisconnected:
stateLabel.textColor = .red
stateLabel.text = "Reader Disconnected"
case .unknownCardInserted:
stateLabel.textColor = .red
stateLabel.text = "Unknown Card Inserted"
case .cardWithoutCertificatesInserted:
stateLabel.textColor = .red
stateLabel.text = "SITHS Card Without Certificates Inserted"
case .readerConnected:
stateLabel.textColor = .blue
stateLabel.text = "Reader Connected"
case .cardInserted(let certificates):
// We have a set of at least one SITHS certificate (see the `SITHSCardCertificate` struct for more information)
let strings = certificates.map { certificate in
return "• \(certificate.cardNumber) \(certificate.serialString) \(certificate.subject[.commonName] ?? "[No common name]")"
}
stateLabel.textColor = .green
stateLabel.text = "SITHS Card Inserted:\n\(strings.joined(separator: "\n"))"
}
}
}
}
要求
注意 Precise SDK 文档中关于启用“支持多个外部配件协议”的特殊说明。
安装
SITHSManager 可通过 CocoaPods 获取。要安装它,只需将以下行添加到 Podfile 中
pod "SITHSManager"
作者
Martin Alléus, Appcorn AB, [email protected]
许可证
版权所有(c)2019 Svensk e-identitet AB。SITHSManager 在 MIT 许可下可用。有关更多信息,请参阅 LICENSE 文件。