ViewController
class ViewController : UIViewController, TextInputViewControllerProtocol
extension ViewController : UIPickerViewDelegate, UIPickerViewDataSource
extension ViewController: ToolbarUIPickerViewDelegateProtocol
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 TKSmartCard class .
Declaration
Swift
private let abcTKSmartCard: ABCTKSmartCard
-
Global array of Card Terminals
Declaration
Swift
private var terminals: [String]
-
Current selected Card Terminal
Declaration
Swift
private var currentTerminal: String
-
Flag indicating if connected to a Card or not
Declaration
Swift
private var connected: Bool
-
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 Refresh UIButton
Declaration
Swift
@IBOutlet weak var buttonRefresh: UIButton!
-
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 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
-
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 Refresh button. Lists all AB Circle USB readers (if any).
Declaration
Swift
@IBAction func onRefresh(_ sender: UIButton)
Parameters
sender
sender
-
Updates the list of Card Terminals. Gets the latest readerlist 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
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) (Note: currently disabled)
Declaration
Swift
@IBAction func onSendEscapeCommand(_ 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: String)
Parameters
newTerminal
New terminal selected on the UI
-
Compares 2 Card Terminals array lists and determines if there are changes
Declaration
Swift
private func terminalsChanged(terminalList1: [String], terminalList2: [String]) -> Bool
Parameters
terminalList1
CardTerminal list 1
terminalList2
CardTerminal list 2
Return Value
True if changes were found, else false
-
sendAPDUThroughBasicChannel(apdu:
Asynchronous) Sends an APDU through a card’s basic channel and receives the response.
Declaration
Swift
private func sendAPDUThroughBasicChannel(apdu: String) async
Parameters
apdu
APDU in hexadecimal string form
-
Sends an Escape command to a connected card (Note: currently disabled)
Declaration
Swift
private func sendEscapeCommand(escapeCommand: String)
Parameters
escapeCommand
Escape command in hexadecimal string form
-
connect()
AsynchronousConnects to a card in the selected terminal (Note: ignores protocol at this moment)
Declaration
Swift
private func connect() async
-
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()