Skip to content

Instantly share code, notes, and snippets.

@paulw11
Last active March 16, 2017 03:10
Show Gist options
  • Save paulw11/2db3579e9fdabc9bd622a45f6ba5cd54 to your computer and use it in GitHub Desktop.
Save paulw11/2db3579e9fdabc9bd622a45f6ba5cd54 to your computer and use it in GitHub Desktop.
//
// CaptuvoManager.swift
//
import Foundation
class CaptuvoManager: NSObject, CaptuvoEventsProtocol {
static let sharedManager = CaptuvoManager()
static let batteryReadyNotification = Notification.Name("BatteryReady")
static let msrReadyNotification = Notification.Name("MSRReady")
static let scannerReadyNotification = Notification.Name("ScannerReady")
static let batteryDetailNotification = Notification.Name("BatteryDetail")
static let decoderDataReceivedNotification = Notification.Name("DataReceived")
static let msrDataReceivedNotification = Notification.Name("MSRDataReceived")
private let notificationCenter = NotificationCenter.default
override init() {
super.init()
Captuvo.sharedCaptuvoDevice().addDelegate(self)
Captuvo.sharedCaptuvoDevice().startDecoderHardware()
Captuvo.sharedCaptuvoDevice().startMSRHardware()
Captuvo.sharedCaptuvoDevice().setMSRTrackSelection(TrackSelectionRequire1and2)
Captuvo.sharedCaptuvoDevice().startPMHardware()
}
func decoderDataReceived(_ data: String!) {
self.notificationCenter.post(name: CaptuvoManager.decoderDataReceivedNotification, object: self, userInfo: ["data":data])
}
func msrStringDataReceived(_ data: String!, validData status: Bool) {
self.notificationCenter.post(name: CaptuvoManager.msrDataReceivedNotification, object: self, userInfo: ["data":data, "validData":status])
}
func pmReady(){
self.notificationCenter.post(name: CaptuvoManager.batteryReadyNotification, object: self, userInfo:nil)
}
func msrReady() {
self.notificationCenter.post(name: CaptuvoManager.msrReadyNotification, object: self, userInfo:nil)
}
func decoderReady() {
self.notificationCenter.post(name: CaptuvoManager.scannerReadyNotification, object: self, userInfo:nil)
}
func responseBatteryDetailInformation(batteryInfo:cupertinoBatteryDetailInfo)
{
self.notificationCenter.post(name: CaptuvoManager.batteryDetailNotification, object: self, userInfo: ["batteryInfo":batteryInfo])
}
func captuvoConnected(){
Captuvo.sharedCaptuvoDevice().startDecoderHardware()
Captuvo.sharedCaptuvoDevice().startMSRHardware()
Captuvo.sharedCaptuvoDevice().startPMHardware()
}
func captuvoDisconnected()
{
Captuvo.sharedCaptuvoDevice().stopDecoderHardware()
Captuvo.sharedCaptuvoDevice().stopMSRHardware();
Captuvo.sharedCaptuvoDevice().stopPMHardware()
}
}
//
// MyTabBarController.swift
// SwiftSample.
//
import UIKit
class MyTabBarController: UITabBarController {
var tab1: Tab1ViewController?
var tab2: Tab2ViewController?
var tab3: Tab3ViewController?
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
let manager = CaptuvoManager.sharedManager //
let notificationCenter = NotificationCenter.default
notificationCenter.addObserver(self, selector: #selector(decoderDataReceived(_:)), name: CaptuvoManager.decoderDataReceivedNotification, object: manager)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
if let destvc = segue.destination as? Tab1ViewController {
self.tab1 = destvc
} else if let destvc = segue.destination as Tab2ViewController {
self.tab2 = destvc
} else if let destvc = segue.destination as Tab3ViewController {
self.tab3 = destvc
}
}
@objc func decoderDataReceived(_ notification: Notification) {
guard let tab1 = self.tab1,
let tab2 = self.tab2,
let tab3 = self.tab3 else {
return
}
if let data = notification.userInfo?["data"] as? String {
if tab3.someSwitch.on {
tab1.someLabel.text = data
} else {
tab2.someLabel.text = data + " x 1"
}
}
}
}
//
// ViewController.swift
// SwiftSample
//
// Created by zhou shadow on 5/6/15.
// Copyright (c) 2015 Honeywell Inc. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var barcodelbl:UILabel!
@IBOutlet weak var msrlbl:UILabel!
@IBOutlet weak var versionlbl:UILabel!
@IBOutlet weak var batterlbl:UILabel!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let manager = CaptuvoManager.sharedManager //
let notificationCenter = NotificationCenter.default
notificationCenter.addObserver(self, selector: #selector(decoderDataReceived(_:)), name: CaptuvoManager.decoderDataReceivedNotification, object: manager)
notificationCenter.addObserver(self, selector: #selector(msrStringDataReceived(_:)), name: CaptuvoManager.msrDataReceivedNotification, object: manager)
notificationCenter.addObserver(self, selector: #selector(pmReady(_:)), name: CaptuvoManager.batteryReadyNotification, object: manager)
notificationCenter.addObserver(self, selector: #selector(msrReady(_:)), name: CaptuvoManager.msrReadyNotification, object: manager)
notificationCenter.addObserver(self, selector: #selector(pmReady(_:)), name: CaptuvoManager.batteryReadyNotification, object: manager)
notificationCenter.addObserver(self, selector: #selector(msrReady(_:)), name: CaptuvoManager.msrReadyNotification, object: manager)
notificationCenter.addObserver(self, selector: #selector(decoderReady(_:)), name: CaptuvoManager.scannerReadyNotification, object: manager)
notificationCenter.addObserver(self, selector: #selector(pmReady(_:)), name: CaptuvoManager.batteryDetailNotification, object: manager)
let infoDictionary = Bundle.main.infoDictionary
//let infoDictionary: AnyObject? = ["CFBundleShortVersionString"]
let minorVersion : AnyObject? = infoDictionary! ["CFBundleVersion"] as AnyObject?
let appversion = minorVersion as! String
barcodelbl.text = "Barcode information"
msrlbl.text = "MSR Information"
versionlbl.text = "App version: \(appversion) \nSDK Version: \(Captuvo.sharedCaptuvoDevice().getSDKshortVersion())"
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@objc func decoderDataReceived(_ notification: Notification) {
if let data = notification.userInfo?["data"] as? String {
barcodelbl.text = data
}
}
@objc func msrStringDataReceived(_ notification: Notification) {
if let data = notification.userInfo?["data"] as? String {
msrlbl.text = data
}
}
@objc func pmReady(_ notification: Notification){
batterlbl.text = "Battery is Ready"
}
@objc func msrReady(_ notification: Notification) {
msrlbl.text = "MSR is Ready"
}
@objc func decoderReady(_ notification: Notification) {
barcodelbl.text = "Scanner is Ready"
}
@objc func responseBatteryDetailInformation(_ notification: Notification)
{
if let batteryDetail = notification.userInfo?["batteryInfo"] as? cupertinoBatteryDetailInfo {
batterlbl.text="Battery: \(batteryInfo.percentage) %";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment