7.8 Sample Project Tutorial
53
• Implement protocol delegate IDT_NEO2Delegate::deviceDisconnected() and IDT_NEO2Delegate::device
←
-
Connected() to monitor connect/disconnect events and modify our connection label upon change.
Reference:
Implement Optional Delegate Protocols
func setConnectionStatus(_ status: String, backgroundColor: UIColor) {
connectionStatus.text = status;
connectionStatus.backgroundColor = backgroundColor
}
func appendMessageToLog(_ message: String) {
logTextView.text =
"
\
n"
+ (logTextView.text) +
"
\
n"
+ (message)
logTextView.scrollRangeToVisible(NSRange(location: 0, length: 0))
}
func displayReturnError(_ operation: String, rt: RETURN_CODE) {
let message = op
" ERROR: ID-"
+ String(describing: rt) +
"Message: "
+ (
().device_getResponseCodeString(Int32(rt.rawValue)))
appendMessageToLog(message)
}
func deviceConnected() {
setConnectionStatus(
"Connected"
, backgroundColor: UIColor.green)
appendMessageToLog("NEO2 Connected
\
nFramework Version:" + IDT_Device.sdk_version())
}
func deviceDisconnected() {
setConnectionStatus(
"Disconnected"
, backgroundColor: UIColor.red)
}
• Implement protocol delegate swipeMSRData:() to receive card swipe data. Reference:
func swipeMSRData(_ cardData:
!) {
NSLog(
"--MSR event received, type: "
+ String(describing: cardData.event) +
" data: "
+ cardData.
encTrack1.hexEncodedString())
switch
cardData.event {
case
EVENT_MSR_CARD_DATA:
switch
cardData.captureEncodeType {
case
CAPTURE_ENCODE_TYPE_ISOABA:
appendMessageToLog(
"Encode Type: ISO/ABA"
)
case
CAPTURE_ENCODE_TYPE_AAMVA:
appendMessageToLog(
"Encode Type: AA/MVA"
)
case CAPTURE_ENCODE_TYPE_Other:
appendMessageToLog("Encode Type: Other")
case CAPTURE_ENCODE_TYPE_Raw:
appendMessageToLog("Encode Type: Raw")
case CAPTURE_ENCODE_TYPE_JIS_I:
appendMessageToLog("Encode Type: CAPTURE_ENCODE_TYPE_JIS_I")
case CAPTURE_ENCODE_TYPE_JIS_II:
appendMessageToLog("Encode Type: CAPTURE_ENCODE_TYPE_JIS_II")
default:
appendMessageToLog("Encode Type: UNKWOWN")
}
switch cardData.captureEncryptType {
case
CAPTURE_ENCRYPT_TYPE_AES:
appendMessageToLog(
"Encrypt Type: AES"
)
case CAPTURE_ENCRYPT_TYPE_TDES:
appendMessageToLog("Encrypt Type: TDES")
case CAPTURE_ENCRYPT_TYPE_NO_ENCRYPTION:
appendMessageToLog("Encrypt Type: NONE")
default:
appendMessageToLog("Encrypt Type: UNKNOWN")
}
appendMessageToLog("Full card data: " + (cardData.cardData == nil ? "N/A" : cardData.cardData.
hexEncodedString()))
appendMessageToLog("Track 1: " + (cardData.track1 == nil ? "N/A" : cardData.track1))
appendMessageToLog("Track 2: " +
(cardData.track2 == nil ? "N/A" : cardData.track2))
appendMessageToLog("Track 3: " + (cardData.track3 == nil ? "N/A" : cardData.track3))
appendMessageToLog("Length Track 1: " + cardData.track1Length.description)
appendMessageToLog("Length Track 2: " + cardData.track2Length.description)
appendMessageToLog("Length Track 3: " + cardData.track3Length.description)
appendMessageToLog("Encoded Track 1: " + (cardData.encTrack1 == nil ? "N/A" : cardData.encTrack1.
hexEncodedString()))
IDTech iOS SDK Guide for NEO2 #80152802-001