Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 31 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ca-cleversolutions-zebraprinter",
"version": "0.0.4",
"version": "0.0.5",
"description": "Zebra Printer Cordova Plugin for iOS and Android",
"cordova": {
"id": "ca-cleversolutions-zebraprinter",
Expand Down
36 changes: 16 additions & 20 deletions src/ios/ZebraPrinter/ZebraPrinterPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import ExternalAccessory
class ZebraPrinterPlugin: CDVPlugin {
var printerConnection: ZebraPrinterConnection?
var printer: ZebraPrinter?

/**
* Discover connectable zebra printers
*
Expand All @@ -14,7 +14,7 @@ class ZebraPrinterPlugin: CDVPlugin {
DispatchQueue.global(qos: .background).async {
let manager = EAAccessoryManager.shared()
let accessories = manager.connectedAccessories

var devices = [Any]()
accessories.forEach { (accessory) in
let name = accessory.name
Expand All @@ -36,7 +36,7 @@ class ZebraPrinterPlugin: CDVPlugin {
)
}
}

/**
* Get the status of the printer we are currently connected to
*
Expand All @@ -54,7 +54,7 @@ class ZebraPrinterPlugin: CDVPlugin {
status["isHeadOpen"] = false
status["isHeadCold"] = false
status["isPartialFormatInProgress"] = false

if(self.printerConnection != nil && self.printerConnection!.isConnected() && self.printer != nil){
let zebraPrinterStatus = try? self.printer?.getCurrentStatus()
if(zebraPrinterStatus != nil){
Expand All @@ -69,7 +69,7 @@ class ZebraPrinterPlugin: CDVPlugin {
NSLog("Printer Not Ready.")
}
}

status["connected"] = true
status["isReadyToPrint"] = zebraPrinterStatus?.isReadyToPrint
status["isPaused"] = zebraPrinterStatus?.isPaused
Expand All @@ -80,7 +80,7 @@ class ZebraPrinterPlugin: CDVPlugin {
status["isHeadOpen"] = zebraPrinterStatus?.isHeadOpen
status["isHeadCold"] = zebraPrinterStatus?.isHeadCold
status["isPartialFormatInProgress"] = zebraPrinterStatus?.isPartialFormatInProgress

NSLog("ZebraPrinter:: returning status")
let pluginResult = CDVPluginResult(
status: CDVCommandStatus_OK,
Expand Down Expand Up @@ -119,7 +119,7 @@ class ZebraPrinterPlugin: CDVPlugin {
}
}
}

/**
* Print the cpcl
*
Expand All @@ -130,10 +130,6 @@ class ZebraPrinterPlugin: CDVPlugin {
if( self.isConnected()){
let data = cpcl.data(using: .utf8)
var error: NSError?
// it seems self.isConnected() can lie if the printer has power cycled
// a workaround is to close and reopen the connection
self.printerConnection!.close()
self.printerConnection!.open()
self.printerConnection!.write(data, error:&error)
if error != nil{
NSLog("ZebraPrinter:: error printing -> " + (error?.localizedDescription ?? "Unknonwn Error"))
Expand Down Expand Up @@ -167,7 +163,7 @@ class ZebraPrinterPlugin: CDVPlugin {
}
}
}

/**
* Check if we are connectd to the printer or not
*
Expand Down Expand Up @@ -211,29 +207,29 @@ class ZebraPrinterPlugin: CDVPlugin {
)
return
}

NSLog("ZebraPrinter:: connecting to " + address)

//try to close an existing connection
if(self.printerConnection != nil){
self.printerConnection?.close()
}

//clear out our existing printer & connection
self.printerConnection = nil;
self.printer = nil;

//create and open a new connection
self.printerConnection = MfiBtPrinterConnection(serialNumber: address)
NSLog("ZebraPrinter:: got connection. opening...")
self.printerConnection?.open()
NSLog("ZebraPrinter:: opened connection")

if( self.isConnected()){
NSLog("ZebraPrinter:: getting printer")
self.printer = try? ZebraPrinterFactory.getInstance(self.printerConnection as? NSObjectProtocol & ZebraPrinterConnection)
NSLog("ZebraPrinter:: got printer")

if(self.printer == nil)
{
NSLog("ZebraPrinter:: nil printer")
Expand Down Expand Up @@ -281,13 +277,13 @@ class ZebraPrinterPlugin: CDVPlugin {
self.printerConnection = nil
self.printer = nil
}

let pluginResult = CDVPluginResult(
status: CDVCommandStatus_OK
)
self.commandDelegate!.send(
pluginResult,
callbackId: command.callbackId
)
}
}
}