Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
class DetailViewController: UIViewController,ScanApiHelperDelegate {
let noScannerConnected = "No scanner connected"
var scanners : [NSString] = []
@IBOutlet weak var connectionStatus: UILabel!
@IBOutlet weak var decodedData: UITextField!
var detailItem: AnyObject?
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
ScanApiHelper.sharedScanApiHelper().pushDelegate(self)
displayScanners()
}
override func viewDidDisappear(animated: Bool) {
ScanApiHelper.sharedScanApiHelper().popDelegate(self)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func displayScanners(){
if let status = connectionStatus {
status.text = ""
for(var scanner) in scanners {
status.text = status.text! + scanner + "\n"
}
if(scanners.count == 0){
status.text = noScannerConnected
}
}
}
// MARK: - ScanApiHelperDelegate
func onDecodedDataResult(result: Int, device: DeviceInfo!, decodedData: ISktScanDecodedData!) {
println("onDecodedDataResult in the detail view")
if result==ESKT_NOERROR {
let rawData = decodedData.getData()
let rawDataSize = decodedData.getDataSize()
let data = NSData(bytes: rawData, length: Int(rawDataSize))
println("Size: \(rawDataSize)")
println("data: \(data)")
let str = NSString(data: data, encoding: NSUTF8StringEncoding)
let string = str as String
println("Decoded Data \(string)")
self.decodedData.text = string
}
}
func onDeviceArrival(result: SKTRESULT, device deviceInfo: DeviceInfo!) {
println("onDeviceArrival in the detail view")
scanners.append(deviceInfo.getName())
displayScanners()
}
func onDeviceRemoval(deviceRemoved: DeviceInfo!) {
println("onDeviceRemoval in the detail view")
var newScanners : [String] = []
for (var scanner) in scanners{
if(scanner != deviceRemoved.getName()){
newScanners.append(scanner)
}
}
scanners=newScanners
displayScanners()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment