tested implementation with ionic native bindings

This commit is contained in:
Evan Moore 2018-05-05 22:33:38 -04:00
parent 66a60b59bf
commit e1934f6b30
9 changed files with 226 additions and 163 deletions

23
native/index.d.ts vendored
View File

@ -3,9 +3,6 @@ export interface Printer {
name: string;
address: string;
}
export interface DiscoveryResult {
printers: Array<Printer>;
}
export interface PrinterStatus {
connected: boolean;
isReadyToPrint?: boolean;
@ -40,19 +37,11 @@ export interface PrinterStatus {
* ```
*/
export declare class ZebraPrinter extends IonicNativePlugin {
echo(options: {
value: string;
}): Promise<any>;
print(options: {
cpcl: string;
}): Promise<any>;
echo(value: string): Promise<any>;
print(cpcl: string): Promise<any>;
isConnected(): Promise<boolean>;
printerStatus(options: {
MACAddress: string;
}): Promise<PrinterStatus>;
connect(options: {
MACAddress: string;
}): Promise<boolean>;
disconnect(): Promise<boolean>;
discover(): Promise<DiscoveryResult>;
printerStatus(adderss: string): Promise<PrinterStatus>;
connect(adress: string): Promise<any>;
disconnect(): Promise<any>;
discover(): Promise<Array<Printer>>;
}

View File

@ -56,11 +56,11 @@ var ZebraPrinter = (function (_super) {
function ZebraPrinter() {
return _super !== null && _super.apply(this, arguments) || this;
}
ZebraPrinter.prototype.echo = function (options) { return; };
ZebraPrinter.prototype.print = function (options) { return; };
ZebraPrinter.prototype.echo = function (value) { return; };
ZebraPrinter.prototype.print = function (cpcl) { return; };
ZebraPrinter.prototype.isConnected = function () { return; };
ZebraPrinter.prototype.printerStatus = function (options) { return; };
ZebraPrinter.prototype.connect = function (options) { return; };
ZebraPrinter.prototype.printerStatus = function (adderss) { return; };
ZebraPrinter.prototype.connect = function (adress) { return; };
ZebraPrinter.prototype.disconnect = function () { return; };
ZebraPrinter.prototype.discover = function () { return; };
ZebraPrinter.decorators = [
@ -71,13 +71,13 @@ var ZebraPrinter = (function (_super) {
__decorate([
Cordova(),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:paramtypes", [String]),
__metadata("design:returntype", Promise)
], ZebraPrinter.prototype, "echo", null);
__decorate([
Cordova(),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:paramtypes", [String]),
__metadata("design:returntype", Promise)
], ZebraPrinter.prototype, "print", null);
__decorate([
@ -89,13 +89,13 @@ var ZebraPrinter = (function (_super) {
__decorate([
Cordova(),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:paramtypes", [String]),
__metadata("design:returntype", Promise)
], ZebraPrinter.prototype, "printerStatus", null);
__decorate([
Cordova(),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:paramtypes", [String]),
__metadata("design:returntype", Promise)
], ZebraPrinter.prototype, "connect", null);
__decorate([
@ -113,12 +113,12 @@ var ZebraPrinter = (function (_super) {
ZebraPrinter = __decorate([
Plugin({
pluginName: 'ZebraPrinter',
plugin: '',
pluginRef: '',
repo: '',
plugin: 'ca-cleversolutions-zebraprinter',
pluginRef: 'cordova.plugins.zebraPrinter',
repo: 'git@github.com:cleversolutions/cordova-zebra-printer.git',
install: '',
installVariables: [],
platforms: [] // Array of platforms supported, example: ['Android', 'iOS']
platforms: ['Android', 'iOS'] // Array of platforms supported, example: ['Android', 'iOS']
})
], ZebraPrinter);
return ZebraPrinter;

View File

@ -1 +1 @@
{"version":3,"sources":["../../../src/@ionic-native/plugins/zebra-printer/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,UAAA,EAAW,MAAO,eAAA,CAAgB;AAC3C,OAAO,EAAE,MAAA,EAAQ,OAAA,EAAS,iBAAA,EAAkB,MAAO,oBAAA,CAAqB;AAwBxE;;;;;;;;;;;;;;;;;;;;GAoBG;AAWH;IAAkC,gCAAiB;IAAnD;;IAqBA,CAAC;IAnBC,2BAAI,GAAJ,UAAK,OAA0B,IAAkB,MAAM,CAAC,CAAC,CAAC;IAE1D,4BAAK,GAAL,UAAM,OAAyB,IAAkB,MAAM,CAAC,CAAC,CAAC;IAE1D,kCAAW,GAAX,cAAkC,MAAM,CAAC,CAAC,CAAC;IAE3C,oCAAa,GAAb,UAAc,OAA+B,IAA4B,MAAM,CAAC,CAAC,CAAC;IAElF,8BAAO,GAAP,UAAQ,OAA+B,IAAsB,MAAM,CAAC,CAAC,CAAC;IAEtE,iCAAU,GAAV,cAAiC,MAAM,CAAC,CAAC,CAAC;IAE1C,+BAAQ,GAAR,cAAuC,MAAM,CAAC,CAAC,CAAC;IAC3C,uBAAU,GAA0B;QAC3C,EAAE,IAAI,EAAE,UAAU,EAAE;KACnB,CAAC;IACF,kBAAkB;IACX,2BAAc,GAAmE,cAAM,OAAA,EAC7F,EAD6F,CAC7F,CAAC;IAlBA;QADC,OAAO,EAAE;;;;4CACgD;IAE1D;QADC,OAAO,EAAE;;;;6CACgD;IAE1D;QADC,OAAO,EAAE;;;;mDACiC;IAE3C;QADC,OAAO,EAAE;;;;qDACwE;IAElF;QADC,OAAO,EAAE;;;;+CAC4D;IAEtE;QADC,OAAO,EAAE;;;;kDACgC;IAE1C;QADC,OAAO,EAAE;;;;gDACsC;IAdrC,YAAY;QAVxB,MAAM,CAAC;YACN,UAAU,EAAE,cAAc;YAC1B,MAAM,EAAE,EAAE;YACV,SAAS,EAAE,EAAE;YACb,IAAI,EAAE,EAAE;YACR,OAAO,EAAE,EAAE;YACX,gBAAgB,EAAE,EAAE;YACpB,SAAS,EAAE,EAAE,CAAC,4DAA4D;SAC3E,CAAC;OAEW,YAAY,CAqBxB;IAAD,mBAAC;CArBD,AAqBC,CArBiC,iBAAiB,GAqBlD;SArBY,YAAY","file":"index.js","sourceRoot":"","sourcesContent":["/**\n * This is a template for new plugin wrappers\n *\n * TODO:\n * - Add/Change information below\n * - Document usage (importing, executing main functionality)\n * - Remove any imports that you are not using\n * - Remove all the comments included in this template, EXCEPT the @Plugin wrapper docs and any other docs you added\n * - Remove this note\n *\n */\nimport { Injectable } from '@angular/core';\nimport { Plugin, Cordova, IonicNativePlugin } from '@ionic-native/core';\n\nexport interface Printer {\n name: string;\n address: string;\n}\n\nexport interface DiscoveryResult {\n printers: Array<Printer>;\n}\n\nexport interface PrinterStatus {\n connected: boolean;\n isReadyToPrint?: boolean;\n isPaused?: boolean;\n isReceiveBufferFull?: boolean;\n isRibbonOut?: boolean;\n isPaperOut?: boolean;\n isHeadTooHot?: boolean;\n isHeadOpen?: boolean;\n isHeadCold?: boolean;\n isPartialFormatInProgress?: boolean;\n}\n\n/**\n * @name Zebra Printer\n * @description\n * This plugin does something\n *\n * @usage\n * ```typescript\n * import { ZebraPrinter } from '@ionic-native/zebra-printer';\n *\n *\n * constructor(private zebraPrinter: ZebraPrinter) { }\n *\n * ...\n *\n *\n * this.zebraPrinter.functionName('Hello', 123)\n * .then((res: any) => console.log(res))\n * .catch((error: any) => console.error(error));\n *\n * ```\n */\n@Plugin({\n pluginName: 'ZebraPrinter',\n plugin: '', // npm package name, example: cordova-plugin-camera\n pluginRef: '', // the variable reference to call the plugin, example: navigator.geolocation\n repo: '', // the github repository URL for the plugin\n install: '', // OPTIONAL install command, in case the plugin requires variables\n installVariables: [], // OPTIONAL the plugin requires variables\n platforms: [] // Array of platforms supported, example: ['Android', 'iOS']\n})\n\nexport class ZebraPrinter extends IonicNativePlugin {\n @Cordova()\n echo(options: { value: string }): Promise<any> { return; }\n @Cordova()\n print(options: { cpcl: string }): Promise<any> { return; }\n @Cordova()\n isConnected(): Promise<boolean> { return; }\n @Cordova()\n printerStatus(options: { MACAddress: string }): Promise<PrinterStatus> { return; }\n @Cordova()\n connect(options: { MACAddress: string }): Promise<boolean> { return; }\n @Cordova()\n disconnect(): Promise<boolean> { return; }\n @Cordova()\n discover(): Promise<DiscoveryResult> { return; }\nstatic decorators: DecoratorInvocation[] = [\n{ type: Injectable },\n];\n/** @nocollapse */\nstatic ctorParameters: () => ({type: any, decorators?: DecoratorInvocation[]}|null)[] = () => [\n];\n}\n\ninterface DecoratorInvocation {\n type: Function;\n args?: any[];\n}\n"]}
{"version":3,"sources":["../../../src/@ionic-native/plugins/zebra-printer/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,UAAA,EAAW,MAAO,eAAA,CAAgB;AAC3C,OAAO,EAAE,MAAA,EAAQ,OAAA,EAAS,iBAAA,EAAkB,MAAO,oBAAA,CAAqB;AAoBxE;;;;;;;;;;;;;;;;;;;;GAoBG;AAWH;IAAkC,gCAAiB;IAAnD;;IAqBA,CAAC;IAnBC,2BAAI,GAAJ,UAAK,KAAa,IAAmB,MAAM,CAAC,CAAC,CAAC;IAE9C,4BAAK,GAAL,UAAM,IAAY,IAAmB,MAAM,CAAC,CAAC,CAAC;IAE9C,kCAAW,GAAX,cAAkC,MAAM,CAAC,CAAC,CAAC;IAE3C,oCAAa,GAAb,UAAc,OAAe,IAA4B,MAAM,CAAC,CAAC,CAAC;IAElE,8BAAO,GAAP,UAAQ,MAAc,IAAkB,MAAM,CAAC,CAAC,CAAC;IAEjD,iCAAU,GAAV,cAA6B,MAAM,CAAC,CAAC,CAAC;IAEtC,+BAAQ,GAAR,cAAsC,MAAM,CAAC,CAAC,CAAC;IAC1C,uBAAU,GAA0B;QAC3C,EAAE,IAAI,EAAE,UAAU,EAAE;KACnB,CAAC;IACF,kBAAkB;IACX,2BAAc,GAAmE,cAAM,OAAA,EAC7F,EAD6F,CAC7F,CAAC;IAlBA;QADC,OAAO,EAAE;;;;4CACoC;IAE9C;QADC,OAAO,EAAE;;;;6CACoC;IAE9C;QADC,OAAO,EAAE;;;;mDACiC;IAE3C;QADC,OAAO,EAAE;;;;qDACwD;IAElE;QADC,OAAO,EAAE;;;;+CACuC;IAEjD;QADC,OAAO,EAAE;;;;kDAC4B;IAEtC;QADC,OAAO,EAAE;;;;gDACqC;IAdpC,YAAY;QAVxB,MAAM,CAAC;YACN,UAAU,EAAE,cAAc;YAC1B,MAAM,EAAE,iCAAiC;YACzC,SAAS,EAAE,8BAA8B;YACzC,IAAI,EAAE,0DAA0D;YAChE,OAAO,EAAE,EAAE;YACX,gBAAgB,EAAE,EAAE;YACpB,SAAS,EAAE,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC,4DAA4D;SAC3F,CAAC;OAEW,YAAY,CAqBxB;IAAD,mBAAC;CArBD,AAqBC,CArBiC,iBAAiB,GAqBlD;SArBY,YAAY","file":"index.js","sourceRoot":"","sourcesContent":["/**\n * This is a template for new plugin wrappers\n *\n * TODO:\n * - Add/Change information below\n * - Document usage (importing, executing main functionality)\n * - Remove any imports that you are not using\n * - Remove all the comments included in this template, EXCEPT the @Plugin wrapper docs and any other docs you added\n * - Remove this note\n *\n */\nimport { Injectable } from '@angular/core';\nimport { Plugin, Cordova, IonicNativePlugin } from '@ionic-native/core';\n\nexport interface Printer {\n name: string;\n address: string;\n}\n\nexport interface PrinterStatus {\n connected: boolean;\n isReadyToPrint?: boolean;\n isPaused?: boolean;\n isReceiveBufferFull?: boolean;\n isRibbonOut?: boolean;\n isPaperOut?: boolean;\n isHeadTooHot?: boolean;\n isHeadOpen?: boolean;\n isHeadCold?: boolean;\n isPartialFormatInProgress?: boolean;\n}\n\n/**\n * @name Zebra Printer\n * @description\n * This plugin does something\n *\n * @usage\n * ```typescript\n * import { ZebraPrinter } from '@ionic-native/zebra-printer';\n *\n *\n * constructor(private zebraPrinter: ZebraPrinter) { }\n *\n * ...\n *\n *\n * this.zebraPrinter.functionName('Hello', 123)\n * .then((res: any) => console.log(res))\n * .catch((error: any) => console.error(error));\n *\n * ```\n */\n@Plugin({\n pluginName: 'ZebraPrinter',\n plugin: 'ca-cleversolutions-zebraprinter', // npm package name, example: cordova-plugin-camera\n pluginRef: 'cordova.plugins.zebraPrinter', // the variable reference to call the plugin, example: navigator.geolocation\n repo: 'git@github.com:cleversolutions/cordova-zebra-printer.git', // the github repository URL for the plugin\n install: '', // OPTIONAL install command, in case the plugin requires variables\n installVariables: [], // OPTIONAL the plugin requires variables\n platforms: ['Android', 'iOS'] // Array of platforms supported, example: ['Android', 'iOS']\n})\n\nexport class ZebraPrinter extends IonicNativePlugin {\n @Cordova()\n echo(value: string ): Promise<any> { return; }\n @Cordova()\n print(cpcl: string ): Promise<any> { return; }\n @Cordova()\n isConnected(): Promise<boolean> { return; }\n @Cordova()\n printerStatus(adderss: string): Promise<PrinterStatus> { return; }\n @Cordova()\n connect(adress: string): Promise<any> { return; }\n @Cordova()\n disconnect(): Promise<any> { return; }\n @Cordova()\n discover(): Promise<Array<Printer>> { return; }\nstatic decorators: DecoratorInvocation[] = [\n{ type: Injectable },\n];\n/** @nocollapse */\nstatic ctorParameters: () => ({type: any, decorators?: DecoratorInvocation[]}|null)[] = () => [\n];\n}\n\ninterface DecoratorInvocation {\n type: Function;\n args?: any[];\n}\n"]}

View File

@ -1 +1 @@
[{"__symbolic":"module","version":3,"metadata":{"Printer":{"__symbolic":"interface"},"DiscoveryResult":{"__symbolic":"interface"},"PrinterStatus":{"__symbolic":"interface"},"ZebraPrinter":{"__symbolic":"class","extends":{"__symbolic":"reference","module":"@ionic-native/core","name":"IonicNativePlugin"},"decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@ionic-native/core","name":"Plugin"},"arguments":[{"pluginName":"ZebraPrinter","plugin":"","pluginRef":"","repo":"","install":"","installVariables":[],"platforms":[]}]},{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable"}}],"members":{"echo":[{"__symbolic":"method","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@ionic-native/core","name":"Cordova"}}]}],"print":[{"__symbolic":"method","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@ionic-native/core","name":"Cordova"}}]}],"isConnected":[{"__symbolic":"method","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@ionic-native/core","name":"Cordova"}}]}],"printerStatus":[{"__symbolic":"method","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@ionic-native/core","name":"Cordova"}}]}],"connect":[{"__symbolic":"method","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@ionic-native/core","name":"Cordova"}}]}],"disconnect":[{"__symbolic":"method","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@ionic-native/core","name":"Cordova"}}]}],"discover":[{"__symbolic":"method","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@ionic-native/core","name":"Cordova"}}]}]}}}},{"__symbolic":"module","version":1,"metadata":{"Printer":{"__symbolic":"interface"},"DiscoveryResult":{"__symbolic":"interface"},"PrinterStatus":{"__symbolic":"interface"},"ZebraPrinter":{"__symbolic":"class","extends":{"__symbolic":"reference","module":"@ionic-native/core","name":"IonicNativePlugin"},"decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@ionic-native/core","name":"Plugin"},"arguments":[{"pluginName":"ZebraPrinter","plugin":"","pluginRef":"","repo":"","install":"","installVariables":[],"platforms":[]}]},{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable"}}],"members":{"echo":[{"__symbolic":"method","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@ionic-native/core","name":"Cordova"}}]}],"print":[{"__symbolic":"method","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@ionic-native/core","name":"Cordova"}}]}],"isConnected":[{"__symbolic":"method","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@ionic-native/core","name":"Cordova"}}]}],"printerStatus":[{"__symbolic":"method","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@ionic-native/core","name":"Cordova"}}]}],"connect":[{"__symbolic":"method","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@ionic-native/core","name":"Cordova"}}]}],"disconnect":[{"__symbolic":"method","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@ionic-native/core","name":"Cordova"}}]}],"discover":[{"__symbolic":"method","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@ionic-native/core","name":"Cordova"}}]}]}}}}]
[{"__symbolic":"module","version":3,"metadata":{"Printer":{"__symbolic":"interface"},"PrinterStatus":{"__symbolic":"interface"},"ZebraPrinter":{"__symbolic":"class","extends":{"__symbolic":"reference","module":"@ionic-native/core","name":"IonicNativePlugin"},"decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@ionic-native/core","name":"Plugin"},"arguments":[{"pluginName":"ZebraPrinter","plugin":"ca-cleversolutions-zebraprinter","pluginRef":"cordova.plugins.zebraPrinter","repo":"git@github.com:cleversolutions/cordova-zebra-printer.git","install":"","installVariables":[],"platforms":["Android","iOS"]}]},{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable"}}],"members":{"echo":[{"__symbolic":"method","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@ionic-native/core","name":"Cordova"}}]}],"print":[{"__symbolic":"method","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@ionic-native/core","name":"Cordova"}}]}],"isConnected":[{"__symbolic":"method","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@ionic-native/core","name":"Cordova"}}]}],"printerStatus":[{"__symbolic":"method","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@ionic-native/core","name":"Cordova"}}]}],"connect":[{"__symbolic":"method","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@ionic-native/core","name":"Cordova"}}]}],"disconnect":[{"__symbolic":"method","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@ionic-native/core","name":"Cordova"}}]}],"discover":[{"__symbolic":"method","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@ionic-native/core","name":"Cordova"}}]}]}}}},{"__symbolic":"module","version":1,"metadata":{"Printer":{"__symbolic":"interface"},"PrinterStatus":{"__symbolic":"interface"},"ZebraPrinter":{"__symbolic":"class","extends":{"__symbolic":"reference","module":"@ionic-native/core","name":"IonicNativePlugin"},"decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@ionic-native/core","name":"Plugin"},"arguments":[{"pluginName":"ZebraPrinter","plugin":"ca-cleversolutions-zebraprinter","pluginRef":"cordova.plugins.zebraPrinter","repo":"git@github.com:cleversolutions/cordova-zebra-printer.git","install":"","installVariables":[],"platforms":["Android","iOS"]}]},{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable"}}],"members":{"echo":[{"__symbolic":"method","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@ionic-native/core","name":"Cordova"}}]}],"print":[{"__symbolic":"method","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@ionic-native/core","name":"Cordova"}}]}],"isConnected":[{"__symbolic":"method","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@ionic-native/core","name":"Cordova"}}]}],"printerStatus":[{"__symbolic":"method","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@ionic-native/core","name":"Cordova"}}]}],"connect":[{"__symbolic":"method","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@ionic-native/core","name":"Cordova"}}]}],"disconnect":[{"__symbolic":"method","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@ionic-native/core","name":"Cordova"}}]}],"discover":[{"__symbolic":"method","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@ionic-native/core","name":"Cordova"}}]}]}}}}]

View File

@ -13,7 +13,7 @@
"cordova-ios"
],
"author": "Evan Moore",
"license": "ISC",
"license": "MIT",
"dependencies": {
"gulp": "^3.9.1"
}

View File

@ -9,9 +9,14 @@
<platform name="ios">
<config-file target="config.xml" parent="/*">
<feature name="ZebraPrinter">
<param name="ios-package" value="ZebraPrinter" />
<param name="ios-package" value="ZebraPrinterPlugin" />
</feature>
</config-file>
<config-file target="*-Info.plist" parent="UISupportedExternalAccessoryProtocols">
<array>
<string>com.zebra.rawport</string>
</array>
</config-file>
<!-- Swift support -->
<dependency id="cordova-plugin-add-swift-support" version="1.7.2"/>
<!-- Zebra SDK -->
@ -38,7 +43,7 @@
<source-file src="src/ios/lib/libZSDK_API.a" framework="true" />
<!-- Plugin Source -->
<source-file src="src/ios/ZebraPrinter.swift" />
<source-file src="src/ios/ZebraPrinterPlugin.swift" />
</platform>
</plugin>

View File

@ -1,128 +0,0 @@
import Foundation
import ExternalAccessory
/**
* Please read the Capacitor iOS Plugin Development Guide
* here: https://capacitor.ionicframework.com/docs/plugins/ios
*/
@objc(ZebraPlugin)
public class ZebraPlugin: CDVPlugin {
var printerConnection: ZebraPrinterConnection?
@objc func echo(command: CDVInvokedUrlCommand) {
var pluginResult = CDVPluginResult(
status: CDVCommandStatus_ERROR
)
let value = command.arguments[0] as? String ?? ""
pluginResult = CDVPluginResult(
status: CDVCommandStatus_OK,
value: value
)
self.commandDelegate!.send(
pluginResult,
callbackId: command.callbackId
)
}
@objc func discover(command: CDVInvokedUrlCommand){
let manager = EAAccessoryManager.shared()
let accessories = manager.connectedAccessories
var devices = [[String:AnyObject]]
accessories.forEach { (accessory) in
let name = accessory.name
var device = [String: AnyObject]
device["name"] = name
device["address"] = accessory.serialNumber
device["manufacturer"] = accessory.manufacturer
device["modelNumber"] = accessory.modelNumber
device["connected"] = accessory.isConnected
devices.append(device)
}
pluginResult = CDVPluginResult(
status: CDVCommandStatus_OK,
printers: devices
)
self.commandDelegate!.send(
pluginResult,
callbackId: command.callbackId
)
}
// @objc func print(_ call: CAPPluginCall) {
// //TODO
// let cpcl = call.getString("cpcl") ?? ""
// if( isConnected()){
// let data = cpcl.data(using: .utf8)
// var error: NSError?
// printerConnection!.write(data, error:&error)
// if let actualError = error{
// call.error("An Error Occurred: \(actualError)")
// }
// }else{
// call.error("no printer connected")
// }
// call.success()
// }
// @objc func isConnected(_ call: CAPPluginCall){
// call.success([
// "connected": isConnected()
// ])
// }
// private func isConnected() -> Bool{
// return (printerConnection != nil && printerConnection!.isConnected())
// }
// @objc func printerStatus(_ call:CAPPluginCall){
// //TODO
// //let address = call.getString("MACAddress") ?? ""
// //Return status
// call.success([
// "connected": true,
// "isReadyToPrint": false,
// "isPaused": false,
// "isReceiveBufferFull": false,
// "isRibbonOut": false,
// "isPaperOut": false,
// "isHeadTooHot": false,
// "isHeadOpen": false,
// "isHeadCold": false,
// "isPartialFormatInProgress": false,
// ])
// }
// @objc func connect(_ call:CAPPluginCall){
// //TODO
// let address = call.getString("MACAddress") ?? ""
// printerConnection = MfiBtPrinterConnection(serialNumber: address)
// printerConnection?.open()
// if( isConnected()){
// let printer = try? ZebraPrinterFactory.getInstance(printerConnection as! NSObjectProtocol & ZebraPrinterConnection)
// if(printer == nil)
// {
// call.error("Error connecting to printer")
// }
// }else{
// call.error("Could not connect to printer")
// }
// call.success([
// "success": true
// ])
// }
// @objc func disconnect(_ call:CAPPluginCall){
// //TODO
// call.success()
// }
}

View File

@ -0,0 +1,181 @@
import Foundation
import ExternalAccessory
@objc(ZebraPrinterPlugin)
class ZebraPrinterPlugin: CDVPlugin {
var printerConnection: ZebraPrinterConnection?
@objc func echo(_ command: CDVInvokedUrlCommand) {
var pluginResult = CDVPluginResult(
status: CDVCommandStatus_ERROR
)
let value = command.arguments[0] as? String ?? ""
pluginResult = CDVPluginResult(
status: CDVCommandStatus_OK,
messageAs: value
)
self.commandDelegate!.send(
pluginResult,
callbackId: command.callbackId
)
}
@objc func discover(_ command: CDVInvokedUrlCommand){
DispatchQueue.global(qos: .background).async {
let manager = EAAccessoryManager.shared()
let accessories = manager.connectedAccessories
var devices = [Any]()
accessories.forEach { (accessory) in
let name = accessory.name
var device = [String: Any]()
device["name"] = name
device["address"] = accessory.serialNumber
device["manufacturer"] = accessory.manufacturer
device["modelNumber"] = accessory.modelNumber
device["connected"] = accessory.isConnected
devices.append(device)
}
let pluginResult = CDVPluginResult(
status: CDVCommandStatus_OK,
messageAs: devices
)
self.commandDelegate!.send(
pluginResult,
callbackId: command.callbackId
)
}
}
@objc func print(_ command: CDVInvokedUrlCommand) {
DispatchQueue.global(qos: .background).async {
let cpcl = command.arguments[0] as? String ?? ""
if( self.isConnected()){
let data = cpcl.data(using: .utf8)
var error: NSError?
self.printerConnection!.write(data, error:&error)
if error != nil{
let pluginResult = CDVPluginResult(
status: CDVCommandStatus_ERROR
)
self.commandDelegate!.send(
pluginResult,
callbackId: command.callbackId
)
}
}else{
let pluginResult = CDVPluginResult(
status: CDVCommandStatus_ERROR
)
self.commandDelegate!.send(
pluginResult,
callbackId: command.callbackId
)
}
let pluginResult = CDVPluginResult(
status: CDVCommandStatus_OK
)
self.commandDelegate!.send(
pluginResult,
callbackId: command.callbackId
)
}
}
@objc func isConnected(_ command: CDVInvokedUrlCommand){
let pluginResult = CDVPluginResult(
status: CDVCommandStatus_OK,
messageAs: isConnected()
)
self.commandDelegate!.send(
pluginResult,
callbackId: command.callbackId
)
}
private func isConnected() -> Bool{
return (printerConnection != nil && printerConnection!.isConnected())
}
// @objc func printerStatus(_ call:CAPPluginCall){
// //TODO
// //let address = call.getString("MACAddress") ?? ""
// //Return status
// call.success([
// "connected": true,
// "isReadyToPrint": false,
// "isPaused": false,
// "isReceiveBufferFull": false,
// "isRibbonOut": false,
// "isPaperOut": false,
// "isHeadTooHot": false,
// "isHeadOpen": false,
// "isHeadCold": false,
// "isPartialFormatInProgress": false,
// ])
// }
@objc func connect(_ command: CDVInvokedUrlCommand){
DispatchQueue.global(qos: .background).async {
var pluginResult = CDVPluginResult(
status: CDVCommandStatus_ERROR
)
let address = command.arguments[0] as? String ?? ""
if(address == ""){
self.commandDelegate!.send(
pluginResult,
callbackId: command.callbackId
)
return
}
self.printerConnection = MfiBtPrinterConnection(serialNumber: address)
self.printerConnection?.open()
if( self.isConnected()){
let printer = try? ZebraPrinterFactory.getInstance(self.printerConnection as! NSObjectProtocol & ZebraPrinterConnection)
if(printer == nil)
{
self.commandDelegate!.send(
pluginResult,
callbackId: command.callbackId
)
return
}
}else{
self.commandDelegate!.send(
pluginResult,
callbackId: command.callbackId
)
return
}
pluginResult = CDVPluginResult(
status: CDVCommandStatus_OK
)
self.commandDelegate!.send(
pluginResult,
callbackId: command.callbackId
)
}
}
@objc func disconnect(_ command: CDVInvokedUrlCommand){
//TODO
if(isConnected()){
printerConnection?.close()
}
let pluginResult = CDVPluginResult(
status: CDVCommandStatus_OK
)
self.commandDelegate!.send(
pluginResult,
callbackId: command.callbackId
)
}
}

View File

@ -5,5 +5,21 @@ exports.echo = function (arg0, success, error) {
};
exports.discover = function (success, error) {
exec(success, error, 'ZebraPrinter', 'discover');
exec(success, error, 'ZebraPrinter', 'discover', []);
};
exports.connect = function (address, success, error) {
exec(success, error, 'ZebraPrinter', 'connect', [address]);
};
exports.disconnect = function (success, error) {
exec(success, error, 'ZebraPrinter', 'disconnect', []);
};
exports.isConnected = function (success, error) {
exec(success, error, 'ZebraPrinter', 'isConnected', []);
};
exports.print = function (cpcl, success, error) {
exec(success, error, 'ZebraPrinter', 'print', [cpcl]);
};