Reader

public final class Reader

Class that represent a smart card reader (either a physical, hardware reader, or a virtual smart card reader).

  • Returns the related SCMEnvironment of this reader.

    Note:

    The reference to the SCMEnvironment from the reader is weak because environment keeps reference to the readers too.

    Declaration

    Swift

    public func getEnv() -> SCMEnvironment?

    Return Value

    the related environment of this reader.

  • Returns the name of the reader.

    Declaration

    Swift

    public func getName() -> String

    Return Value

    The name of the reader.

  • Returns if the card is inserted in the reader.

    Declaration

    Swift

    public func isCardPresent() -> Bool

    Return Value

    true if the card is inserted in the reader, false otherwise.

  • Returns the type of the reader.

    Declaration

    Swift

    public func getType() -> String

    Return Value

    A string representing the type of the reader. It can be one of the following:

    • "usb"
    • "usbc"
    • "bluetooth"
    • "nfc"

  • Returns the type of the reader.

    See also

    ReaderType

    Declaration

    Swift

    public func getType() -> ReaderType

    Return Value

    the type of the reader.

  • Gets the status of the reader.

    See also

    ReaderStatus

    Declaration

    Swift

    public func getStatus() -> ReaderStatus

    Return Value

    the status of the reader.

  • Connects to the card inserted in the reader. This method succeeds only if the card is supported by the middleware.

    Example:

    func onReaderStateChanged(reader: Reader) {
        if (reader.isCardPresent() && reader.getStatus() == .OK) {
            reader.connect() { token, error in
                if let error = error {
                    print("fail to connect to token: " + error.localizedDescription)
                }
                else {
                    // do stuff with your token
                }
            }
        }
    }
    

    Declaration

    Swift

    public func connect(completionHandler: @escaping (_ token: Token?, _ error: NSError?) -> Void)

    Parameters

    completionHandler

    The completion handler to call when the connection is complete. It takes the following parameters:

    • token Token?: the token object connected to the reader.
    • error NSError?: nil if the operation is completed successfully; otherwise an error encapsulates the reason of failure.

    Note

    The completion handler is executed on the same type of DispatchQueue as in the calling code.