ABCCardTerminalMonitor
class ABCCardTerminalMonitor
CardTerminal helper class for monitoring detected CardTerminals.
Monitors for disconnection and battery level. If a delegate has been set will call callback functions once a CardTerminal disconnect or when a CardTerminal hits a pre-set battery threshold level.
-
Delegate, set this to the class acting as delegate for this class using the ABCCardTerminalMonitorProtocol
Declaration
Swift
var delegate: ABCCardTerminalMonitorProtocol?
-
Main instance of the AB Circle Terminal Factory.
Declaration
Swift
private let abcTerminalFactory: ABCircleTerminalFactory
-
CardTerminals to monitor
Declaration
Swift
private var terminalsToMonitor: [String : CardTerminalToMonitor]
-
Timer (used for automatically updating the Card Terminal list and information)
Declaration
Swift
private var timer: DispatchSourceTimer?
-
Timer refresh rate in seconds
Declaration
Swift
private var timerRefreshRateInSeconds: UInt16
-
Battery threshold to monitor
Declaration
Swift
private var batteryThreshold: UInt8
-
Queue for timer
Declaration
Swift
private let timerQueue: DispatchQueue
-
Flag indicating if monitor is running
Declaration
Swift
private var monitorRunning: Bool
-
Initialiser.
Declaration
Swift
init()
-
De-initialiser
Declaration
Swift
deinit
-
Start monitoring CardTerminals using the entered values for refresh rate and battery threshold.
Declaration
Swift
func startMonitoring(refreshRateInSeconds: UInt16 = 1, batteryThreshold: UInt8 = 20)
Parameters
refreshRateInSeconds
Monitor refresh rate in seconds
batteryThreshold
Battery threshold to monitor for
-
Stop monitoring CardTerminals
Declaration
Swift
func stopMonitoring()
-
Flag indicating if the monitor is currently running or not
Declaration
Swift
var isMonitorRunning: Bool { get }
-
Set the battery threshold to monitor for all connected readers. Notes:
- Setting this to 0 will disable monitoring the battery level
Setting a different value from the previous value will reset the notice
Declaration
Swift
func setBatteryThreshold(batteryThreshold: UInt8)
Parameters
batteryThreshold
Threshold value from 0 to 100%
-
Set the monitor refresh rate in seconds. This is the frequency where the monitors updates the information of the monitored CardTerminals. Note: setting this to 0 will disable monitoring completely.
Declaration
Swift
func setMonitorRefreshRate(refreshRateInSeconds: UInt16)
Parameters
refreshRateInSeconds
refresh rate in seconds
-
Function called when the battery threshold of a CardTerminal has been reached If a delegate has been set, will call the implemented callback function of the delegate.
Declaration
Swift
private func onBatteryThresholdReached(terminalName: String, batteryThreshold: UInt8)
Parameters
terminalName
Name of the terminal that reached the battery threshold
batteryThreshold
Value of the battery threshold
-
Function called when a CardTerminal has disconnected If a delegate has been set, will call the implemented callback function of the delegate.
Declaration
Swift
private func onDisconnected(terminalName: String)
Parameters
terminalName
Name of the terminal that has disconnected
-
Starts the CardTerminal monitor
Declaration
Swift
private func startMonitor()
-
Stops the CardTerminal monitor
Declaration
Swift
private func stopMonitor()
-
Callback function called by the timer which does all the monitoring @objc
Declaration
Swift
private func monitorCardTerminals()
-
Checks if a CardTerminal has disconnected
Declaration
Swift
private func checkDisconnectedTerminals(terminals: [CardTerminal])
Parameters
terminals
latest CardTerminal list to check against
-
Checks if a CardTerminal has reached the battery threshold
Declaration
Swift
private func checkBatteryLevel()
-
Removes a monitored CardTerminal from the internal list
Declaration
Swift
private func removeMonitoredTerminal(terminalName: String)
Parameters
terminalName
Name of monitored CardTerminal to remove.
-
Refreshes the internal list of monitored CardTerminals
Declaration
Swift
private func refreshMonitoredTerminals(terminals: [CardTerminal])
Parameters
terminals
latest CardTerminal list to check against