ViewController
class ViewController : UIViewController, TextInputViewControllerProtocol, OptionsViewControllerProtocol, ReaderDiscoveredCallback
extension ViewController : UIPickerViewDelegate, UIPickerViewDataSource
extension ViewController: ToolbarUIPickerViewDelegateProtocol
extension ViewController: ABCCardTerminalMonitorProtocol
Main view controller; controls the main screen Also acts as delegate for the TextInputViewController and OptionsViewControllerProtocol
-
Enumerator holding the possible UI States
See moreDeclaration
Swift
private enum UIState
-
Main instance of the AB Circle Terminal Factory.
Declaration
Swift
private let abcTerminalFactory: ABCircleTerminalFactory
-
Create an instance for Card Terminal monitor
Declaration
Swift
private let abcCardTerminalMonitor: ABCCardTerminalMonitor
-
Global array of Card Terminals
Declaration
Swift
private var terminals: [CardTerminal]
-
Current selected Card Terminal
Declaration
Swift
private weak var currentTerminal: CardTerminal?
-
Current active Card
Declaration
Swift
private var card: Card?
-
Flag indicating if the CardTerminal monitor has started or not
Declaration
Swift
private var monitorStarted: Bool
-
Flag indicating if connected to a Card or not
Declaration
Swift
private var connected: Bool
-
Options storage
Declaration
Swift
private let options: Options
-
Timer (used for automatically updating the Card Terminal list)
Declaration
Swift
private var timer: Timer?
-
Custom Card Terminal UIPickerView with Toolbar
Declaration
Swift
private let terminalPicker: ToolbarUIPickerView
-
Control outlet for custom key UIButton
Declaration
Swift
@IBOutlet weak var customKeyButton: UIButton!
-
Control outlet for terminal UILabel
Declaration
Swift
@IBOutlet weak var labelTerminal: UILabel!
-
Control outlet for terminal NoCaretUITextField
Declaration
Swift
@IBOutlet weak var selectedTerminal: NoCaretUITextField!
-
Control outlet for Discover UIButton
Declaration
Swift
@IBOutlet weak var buttonDiscover: UIButton!
-
Control outlet for Refresh UIButton
Declaration
Swift
@IBOutlet weak var buttonRefresh: UIButton!
-
Control outlet for Monitor UISwitch
Declaration
Swift
@IBOutlet weak var monitorSwitch: UISwitch!
-
Control outlet for protocol UILabel
Declaration
Swift
@IBOutlet weak var labelProtocol: UILabel!
-
Control outlet for protocol T=0 UISwitch
Declaration
Swift
@IBOutlet weak var protocolT0: UISwitch!
-
Control outlet for protocol T=0 label
Declaration
Swift
@IBOutlet weak var labelT0: UILabel!
-
Control outlet for protocol T=1 UISwitch
Declaration
Swift
@IBOutlet weak var protocolT1: UISwitch!
-
Control outlet for protocol T=1 label
Declaration
Swift
@IBOutlet weak var labelT1: UILabel!
-
Control outlet for Mode UILabel
Declaration
Swift
@IBOutlet weak var labelMode: UILabel!
-
Control outlet for mode selection UISegmentedControl
Declaration
Swift
@IBOutlet weak var modeSelector: UISegmentedControl!
-
Control outlet for connect UIButton
Declaration
Swift
@IBOutlet weak var buttonConnect: UIButton!
-
Control outlet for log UIView
Declaration
Swift
@IBOutlet weak var viewLog: UIView!
-
Control outlet for log UIScrollView
Declaration
Swift
@IBOutlet weak var scrollViewLog: UIScrollView!
-
Control outlet for log NoCaretUITextView
Declaration
Swift
@IBOutlet weak var textViewLog: NoCaretUITextView!
-
Control outlet for apdu label UILabel
Declaration
Swift
@IBOutlet weak var apduLabel: UILabel!
-
Control outlet for apdu NoCaretUITextField
Declaration
Swift
@IBOutlet weak var apduTextField: NoCaretUITextField!
-
Control outlet for audo send UIButton
Declaration
Swift
@IBOutlet weak var apduSendButton: UIButton!
-
Control outlet for wait for change UIButton
Declaration
Swift
@IBOutlet weak var waitForChangeButton: UIButton!
-
Control outlet for Mode escape command UILabel
Declaration
Swift
@IBOutlet weak var escapeCommandLabel: UILabel!
-
Control outlet for escape command NoCaretUITextField
Declaration
Swift
@IBOutlet weak var escapeCommandTextField: NoCaretUITextField!
-
Control outlet for escape command send UIButton
Declaration
Swift
@IBOutlet weak var escapeCommandSendButton: UIButton!
-
Called after the controller’s view is loaded into memory. Initialises the local variables, the controls and starts the terminal list updater
Declaration
Swift
override func viewDidLoad()
-
Closes the APDU / Escape Command popup and retrieves its content
Declaration
Swift
func closePopup(textViewContent: String, isApdu: Bool)
Parameters
textViewContent
Textview content from the text view on the popup
isApdu
Flag indicating APDU popup or Escape Command popup
-
Action handler for opening the Options view
Declaration
Swift
@IBAction func onShowOptionsView(_ sender: UIButton)
Parameters
sender
sender (UIButton)
-
Overrride function called when the Custom Key view is preparing (just before opening). Used here to set the initial values of the controls on the Custom Key view.
Declaration
Swift
override func prepare(for segue: UIStoryboardSegue, sender: Any?)
Parameters
segue
Segue being handled
sender
sender
-
Call back function handling the closing of the Options view. Used for either clearing or setting of the Custom Encryption Key used by the AB Circle Terminal Factory. Note: the custom key entered is always saved in the “customKey” class variable, so it can be shown and activated at any time (usage is determined by the “useDefaultKey” flag). Also used for setting the scanBluetooth name and RSSI filter values, CardMonitor values and disabling or enabling of the ACK protocol for terminals that support it (terminals with fw 109.00 or higher).
Declaration
Swift
func onCloseOptionsWindow(options: Options)
Parameters
options
Options as set in the Options view.
-
Callback handler for showing the APDU input view
Declaration
Swift
@objc private func showApduInputView()
-
Callback handler for showing the Escape Command input view
Declaration
Swift
@objc private func showEscapeCommandInputView()
-
Callback handler for handling connection mode change. Enables or disables the protocol fields.
Declaration
Swift
@IBAction func onModeChanged(_ sender: UISegmentedControl)
Parameters
sender
sender
-
Callback handler for handling the Discover button
Declaration
Swift
@IBAction func onDiscoverReaders(_ sender: UIButton)
Parameters
sender
sender
-
Callback handler, called when a reader is discovered (part of the ReaderDiscoveredCallback protocol)
Declaration
Swift
func onReaderDiscovered(reader: ABCSmartCardIO.DiscoveredReader)
Parameters
reader
Discovered reader
-
Callback handler for handling the Disconnect button Disconnect the current selected terminal.
Declaration
Swift
@IBAction func onDisconnectTerminal(_ sender: UIButton)
Parameters
sender
sender
-
Callback handler for handling the Battery button Retrieves and shows the battery level of the current selected terminal.
Declaration
Swift
@IBAction func onGetBatteryLevel(_ sender: UIButton)
Parameters
sender
sender
-
Callback handler for handling the Version button Retrieves and shows the firmware version of the current selected terminal.
Declaration
Swift
@IBAction func onGetFirmwareVersion(_ sender: UIButton)
Parameters
sender
sender
-
Callback handler for handling the Refresh button. Calls the ABC Terminal Factory scanBluetooth() function for scanning and finding AB Circle bluetooth readers.
Declaration
Swift
@IBAction func onRefresh(_ sender: UIButton)
Parameters
sender
sender
-
Enables or disables the CardTerminal monitor
Declaration
Swift
@IBAction func onMonitorChanged(_ sender: UISwitch)
Parameters
sender
UISwitch
-
Starts the CardTerminal monitor
Declaration
Swift
private func startMonitor()
-
Stops the CardTerminal monitor
Declaration
Swift
private func stopMonitor()
-
Starts the card terminal list updater, using a timer. Checks for changes in the card terminal list every second and updates the list if needed.
Declaration
Swift
private func startReaderListUpdater()
-
Callback handler for updating the list of Card Terminals. Gets the latest list from the AB Circle Terminal Factory by calling “terminals.list()” and checks if there are any changes. If there are changes, rebuilds the terminal picker and resets the terminal TextInput box if needed.
Declaration
Swift
@objc private func listReaders()
-
Callback function handling the Protocol T=0 switch. Enables or disables the Connect button.
Declaration
Swift
@IBAction func onProtocolT0ValueChanged(_ sender: UISwitch)
Parameters
sender
sender
-
Callback function handling the Protocol T=1 switch. Enables or disables the Connect button.
Declaration
Swift
@IBAction func onProtocolT1ValueChanged(_ sender: UISwitch)
Parameters
sender
sender
-
Callback function handling the Connect button. If connected, tries to connect; else disconnects.
Declaration
Swift
@IBAction func onConnect(_ sender: Any)
Parameters
sender
sender
-
Callback handler handling the “Send APDU” button. Sends an APDU command to a connected card (if any)
Declaration
Swift
@IBAction func onSendAPDU(_ sender: UIButton)
Parameters
sender
sender
-
Callback handler handling the “Send Escape Command” button. Sends an Escape Command to a connected card (if any)
Declaration
Swift
@IBAction func onSendEscapeCommand(_ sender: UIButton)
Parameters
sender
sender
-
Callback function for handling the “Wait for Change” button. Calls the AB Circle Terminal Factory “waitForChange” function to wait for a card change action on the current selected card terminal. If a change occured, will show the change detected by calling “terminals().list()” function twice with state filters for card insertion and card removal.
Declaration
Swift
@IBAction func onWaitForChangeClicked(_ sender: UIButton)
Parameters
sender
sender
-
Clears the log
Declaration
Swift
@IBAction func onClear(_ sender: UIButton)
Parameters
sender
sender
-
Initialises a text view control with empty text and a default border.
Declaration
Swift
private func initialiseTextView(textView: UITextView)
Parameters
textView
Textview control to initialise
-
(Re-)Selects the current card terminal
Declaration
Swift
private func selectCurrentTerminal(newTerminal: CardTerminal)
Parameters
newTerminal
New terminal selected on the UI
-
Compares 2 CardTerminals array lists and determines if there are changes
Declaration
Swift
private func terminalsChanged(terminalList1: [CardTerminal], terminalList2: [CardTerminal]) -> Bool
Parameters
terminalList1
CardTerminal list 1
terminalList2
CardTerminal list 2
Return Value
True if changes were found, else false
-
Sends an APDU through a card’s basic channel and receives the response.
Declaration
Swift
private func sendAPDUThroughBasicChannel(apdu: String)
Parameters
apdu
APDU in hexadecimal string form
-
Gets the basic channel of a currently connected card
Declaration
Swift
private func getBasicChannel() -> CardChannel?
Return Value
A CardChannel object on success, else nil
-
Creates a CommandAPDU from the entered APDU hexadecimal string
Declaration
Swift
private func getCommandAPDU(apduString: String) -> CommandAPDU?
Parameters
apduString
APDU in hexadecimal string form
Return Value
A CommandAPDU object on success, else nil
-
Sends an Escape command to a connected card
Declaration
Swift
private func sendEscapeCommand(escapeCommand: String)
Parameters
escapeCommand
Escape command in hexadecimal string form
-
Connects to a card in the selected terminal
Declaration
Swift
private func connect()
-
Disconnects from a card (if connected)
Declaration
Swift
private func disconnect()
-
Indicates if Direct Mode is selected
Declaration
Swift
private func selectedModeIsDirect() -> Bool
Return Value
True if Direct Mode is selected, else false
-
Enables groups of UI fields depending on the entered state
Declaration
Swift
private func enableUIFields(state: UIState)
Parameters
state
UI state (see enum UIState in this class for possible values)
-
Enables or disables the main UI fields
Declaration
Swift
private func enableMainFields(enabled: Bool)
Parameters
enabled
True to set the fields as enabled, false to set the fields as disabled
-
Enables or disables the command related UI fields
Declaration
Swift
private func enableCommandFields(enabled: Bool)
Parameters
enabled
True to set the fields as enabled, false to set the fields as disabled
-
Enables or disables the connection related UI fields
Declaration
Swift
private func enableConnectionFields(enabled: Bool, excludeConnect: Bool = false)
Parameters
enabled
True to set the fields as enabled, false to set the fields as disabled
-
Enables or disables the protocol selection related UI fields
Declaration
Swift
private func enableProtocolFields(enabled: Bool)
Parameters
enabled
True to set the fields as enabled, false to set the fields as disabled
-
Output the terminal list to the log ui field
Declaration
Swift
private func outputTerminalsToLog()
-
Add a formatted line to the log ui field
Declaration
Swift
private func addLogLine(format: String, arguments: CVarArg...)
Parameters
format
Line format to use
arguments
Arguments for the format
-
Adds a line to the log ui filed
Declaration
Swift
private func addLogLine(line: String)
Parameters
line
Line to add
-
Scrolls the log ui field contents to the end
Declaration
Swift
private func scrollLogToEnd()
-
Gets the number of components for the picker view. Here always 1, since we only use 1 component.
Declaration
Swift
func numberOfComponents(in pickerView: UIPickerView) -> Int
Parameters
pickerView
UIPickerView to handle
Return Value
Int holding the number of components
-
Returns the number of rows for a component. Here returns the number of rows in the main CardTerminal list (as that is the data source for the UIPickerView)
Declaration
Swift
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int
Parameters
pickerView
An object representing the picker view requesting the data.
component
A zero-indexed number identifying a component of pickerView. Components are numbered left-to-right.
Return Value
Int holding the number of rows for the specified component
-
Called by the picker view when it needs the title to use for a given row in a given component. Here returns the name of the terminal from the terminal list associated with the row as datasource
Declaration
Swift
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String?
Parameters
pickerView
An object representing the picker view requesting the data.
row
A zero-indexed number identifying a row of component. Rows are numbered top-to-bottom.
component
A zero-indexed number identifying a component of pickerView. Components are numbered left-to-right.
Return Value
The string to use as the title of the indicated component row.
-
User tapped ‘Done’ button. Here selects the current terminal and closes the UIPickerView.
Declaration
Swift
func didTapDone()
-
User tapped ‘Cancel’ button. Closes the UIPickerView.
Declaration
Swift
func didTapCancel()
-
Call back function definition to implement by the delegate. Called once when a terminal has hit the battery threshold
Declaration
Swift
func onBatteryThresholdReached(terminalName: String, batteryThreshold: UInt8)
Parameters
terminalName
Name of card terminal hitting the threshold
batteryThreshold
Battery threshold reached
-
Call back function definition to implement by the delegate. Called once when a terminal has disconnected
Declaration
Swift
func onDisconnected(terminalName: String)
Parameters
terminalName
Name of card terminal that has disconnected