@captureid/capacitor-cidprint 0.2.65 → 5.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CaptureidCapacitor3Cidprint.podspec +21 -0
- package/README.md +809 -20
- package/android/.project +2 -2
- package/android/.settings/org.eclipse.buildship.core.prefs +1 -1
- package/android/app/captureid/cidprinterlibrary/1.0.5/cidprinterlibrary-1.0.5.aar +0 -0
- package/android/app/captureid/cidprinterlibrary/1.0.5/cidprinterlibrary-1.0.5.pom +20 -0
- package/android/app/captureid/cidprinterlibrary/1.0.5/cidprinterlibrary-1.0.5.pom.md5 +1 -0
- package/android/app/captureid/cidprinterlibrary/1.0.5/cidprinterlibrary-1.0.5.pom.sha1 +1 -0
- package/android/app/captureid/cidprinterlibrary/maven-metadata.xml +15 -0
- package/android/app/captureid/cidprinterlibrary/maven-metadata.xml.md5 +1 -0
- package/android/app/captureid/cidprinterlibrary/maven-metadata.xml.sha1 +1 -0
- package/android/app/captureid/cidprinterlibrary/maven-metadata.xml.sha256 +1 -0
- package/android/app/captureid/cidprinterlibrary/maven-metadata.xml.sha512 +1 -0
- package/android/app/captureid/supportv1/1.0.1/supportv1-1.0.1.aar +0 -0
- package/android/app/captureid/supportv1/1.0.1/supportv1-1.0.1.pom +9 -0
- package/android/app/captureid/supportv1/1.0.1/supportv1-1.0.1.pom.md5 +1 -0
- package/android/app/captureid/supportv1/1.0.1/supportv1-1.0.1.pom.sha1 +1 -0
- package/android/app/captureid/supportv1/1.0.1/supportv1-1.0.1.pom.sha256 +1 -0
- package/android/app/captureid/supportv1/1.0.1/supportv1-1.0.1.pom.sha512 +1 -0
- package/android/app/captureid/supportv1/maven-metadata-local.xml +12 -0
- package/android/app/captureid/supportv1/maven-metadata.xml +13 -0
- package/android/app/captureid/supportv1/maven-metadata.xml.md5 +1 -0
- package/android/app/captureid/supportv1/maven-metadata.xml.sha1 +1 -0
- package/android/app/captureid/supportv1/maven-metadata.xml.sha256 +1 -0
- package/android/app/captureid/supportv1/maven-metadata.xml.sha512 +1 -0
- package/android/build.gradle +20 -5
- package/android/src/main/java/app/captureid/plugins/cidprint/CIDPrint.java +686 -175
- package/dist/docs.json +1292 -0
- package/dist/esm/configuration.d.ts +26 -0
- package/dist/esm/configuration.js +20 -0
- package/dist/esm/configuration.js.map +1 -0
- package/dist/esm/definitions.d.ts +92 -21
- package/dist/esm/definitions.js +2 -0
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/enums.d.ts +58 -3
- package/dist/esm/enums.js +88 -0
- package/dist/esm/enums.js.map +1 -1
- package/dist/esm/index.d.ts +5 -0
- package/dist/esm/index.js +8 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/printer.d.ts +45 -0
- package/dist/esm/printer.js +1 -0
- package/dist/esm/printer.js.map +1 -0
- package/dist/esm/web.d.ts +77 -5
- package/dist/esm/web.js +102 -49
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.js +234 -48
- package/dist/plugin.js.map +1 -1
- package/ios/Plugin/BluetoothManager.h +46 -0
- package/ios/Plugin/CIDPrint.h +13 -0
- package/ios/Plugin/CIDPrint.m +518 -0
- package/ios/Plugin/{Plugin.h → CIDPrintPlugin.h} +11 -2
- package/ios/Plugin/CIDPrintPlugin.m +31 -0
- package/ios/Plugin/CIDPrinter.h +43 -0
- package/ios/Plugin/Device.h +57 -0
- package/ios/Plugin/Info.plist +8 -0
- package/ios/Plugin/InitResult.h +20 -0
- package/ios/Plugin/PrinterLibraryEvent.h +59 -0
- package/ios/Plugin/ResultClass.h +18 -0
- package/ios/Plugin/libCIDPrinterLibrary.a +0 -0
- package/package.json +19 -16
- package/android/.DS_Store +0 -0
- package/android/.npmignore +0 -1
- package/android/libs/.DS_Store +0 -0
- package/android/libs/cidprinterlibrary.aar +0 -0
- package/ios/Plugin/Plugin.m +0 -8
- package/ios/Plugin/Plugin.swift +0 -17
|
@@ -0,0 +1,518 @@
|
|
|
1
|
+
#import <Foundation/Foundation.h>
|
|
2
|
+
#import <Capacitor/Capacitor.h>
|
|
3
|
+
#import "CIDPrinter.h"
|
|
4
|
+
#import "InitResult.h"
|
|
5
|
+
#import "PrinterLibraryEvent.h"
|
|
6
|
+
#import "CIDPrint.h"
|
|
7
|
+
|
|
8
|
+
@implementation CIDPrint
|
|
9
|
+
|
|
10
|
+
#define LIBRARY_EVENT @"printerLibraryEvent"
|
|
11
|
+
|
|
12
|
+
CAPPluginCall *savedLastCall;
|
|
13
|
+
|
|
14
|
+
-(BOOL) hasRequiredPermissions:(NSArray<NSString*>*)permissions {
|
|
15
|
+
return YES;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
-(NSDictionary*) fromJSONObject:(NSDictionary*)jobj {
|
|
19
|
+
NSMutableDictionary* dict = [[NSMutableDictionary alloc]initWithDictionary:jobj];
|
|
20
|
+
return dict;
|
|
21
|
+
// Iterator<String> keys = jobj.keys();
|
|
22
|
+
// while(keys.hasNext()) {
|
|
23
|
+
// String key = keys.next();
|
|
24
|
+
// try {
|
|
25
|
+
// if(jobj.get(key) instanceof JSONObject) {
|
|
26
|
+
// jobj.put(key, fromJSONObject((JSONObject) jobj.get(key)));
|
|
27
|
+
// }
|
|
28
|
+
// } catch (JSONException e) {
|
|
29
|
+
// Log.d(TAG, "fromJSONObject encounters an error in " + key + " error: " + e.getMessage());
|
|
30
|
+
// }
|
|
31
|
+
// }
|
|
32
|
+
// return JSObject.fromJSONObject(jobj);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
-(void)handleSuccess:(PrinterLibraryEvent*)evt {
|
|
37
|
+
switch([evt getAction]) {
|
|
38
|
+
case LICENSE_ACTIVATION:
|
|
39
|
+
if(savedLastCall != nil) {
|
|
40
|
+
savedLastCall.successHandler([[CAPPluginCallResult alloc]init:[evt getJSONObject]], savedLastCall);
|
|
41
|
+
}
|
|
42
|
+
break;
|
|
43
|
+
default:
|
|
44
|
+
[self notifyListeners:LIBRARY_EVENT data:[evt getJSONObject]];
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
-(void)handleError:(PrinterLibraryEvent*)evt {
|
|
49
|
+
[self notifyListeners:LIBRARY_EVENT data:[evt getJSONObject]];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
-(void)handleNotification:(PrinterLibraryEvent*)evt {
|
|
53
|
+
[self notifyListeners:LIBRARY_EVENT data:[evt getJSONObject]];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
-(void) initCIDPrinterLib:(CAPPluginCall*)call {
|
|
57
|
+
NSLog(@"initCIDPrint");
|
|
58
|
+
self._printerlibrary = CIDPrinter.getSharedObject;
|
|
59
|
+
PrinterLibraryEvent* evt = nil;
|
|
60
|
+
if(self._printerlibrary != nil) {
|
|
61
|
+
[self._printerlibrary addListener:self];
|
|
62
|
+
evt = [self._printerlibrary initialize];
|
|
63
|
+
if([self hasRequiredPermissions:CIDPrinter.getRequiredPermissions]) {
|
|
64
|
+
NSMutableDictionary<NSString*, id>* test;
|
|
65
|
+
call.successHandler([[CAPPluginCallResult alloc]init:[evt getJSONObject]], call);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
evt = [[PrinterLibraryEvent alloc]initWithResultClass:SUCCESS action:INITIALIZE data:[[InitResult alloc]initWithPermissions:CIDPrinter.getRequiredPermissions]];
|
|
69
|
+
call.successHandler([[CAPPluginCallResult alloc]init:[evt getJSONObject]], call);
|
|
70
|
+
} else {
|
|
71
|
+
call.errorHandler([[CAPPluginCallError alloc]init:@"Failed to initialize printer plugin" code:@"" error:nil data:[[NSDictionary alloc]init]]);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
-(void) enableBluetoothPrinting:(CAPPluginCall*)call {
|
|
76
|
+
if(self._printerlibrary != nil) {
|
|
77
|
+
call.keepAlive = YES;
|
|
78
|
+
savedLastCall = call;
|
|
79
|
+
[self addCallback:@"enableBluetoothPrinting" callback:call];
|
|
80
|
+
[self._printerlibrary enableBluetoothPrinting:[call.options objectForKey:@"enable"]];
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
-(void)connectToPreferredPrinter:(CAPPluginCall*)call {
|
|
85
|
+
if(self._printerlibrary != nil) {
|
|
86
|
+
call.keepAlive = YES;
|
|
87
|
+
[self addCallback:@"connectToPreferredPrinter" callback:call];
|
|
88
|
+
[self._printerlibrary connectToPreferredPrinter:[call.options objectForKey:@"mac"]];
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
-(void)printLabelWithObject:(CAPPluginCall*) call {
|
|
93
|
+
if(self._printerlibrary != nil) {
|
|
94
|
+
call.keepAlive = true;
|
|
95
|
+
[self addCallback:@"printLabelWithObject" callback:call];
|
|
96
|
+
[self._printerlibrary print:[call.options objectForKey:@"label"] params:[call.options objectForKey:@"data"]];
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
-(void)printReceiptWithObject:(CAPPluginCall*) call {
|
|
101
|
+
if(self._printerlibrary != nil) {
|
|
102
|
+
call.keepAlive = true;
|
|
103
|
+
[self addCallback:@"printReceiptWithObject" callback:call];
|
|
104
|
+
[self._printerlibrary printReceipt:[call.options objectForKey:@"label"] params:[call.options objectForKey:@"data"]];
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
-(void) printLabel:(CAPPluginCall*)call {
|
|
109
|
+
if(self._printerlibrary != nil) {
|
|
110
|
+
[self addCallback:@"printData" callback:call];
|
|
111
|
+
[self._printerlibrary print:[call.options objectForKey:@"label"]];
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
-(void) discoverDevices:(CAPPluginCall*)call {
|
|
116
|
+
if(self._printerlibrary != nil) {
|
|
117
|
+
call.keepAlive = YES;
|
|
118
|
+
savedLastCall = call;
|
|
119
|
+
[self addCallback:@"discoveredDevices" callback:call];
|
|
120
|
+
[self._printerlibrary discoverDevices];
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
-(void) addCallback:(NSString*)functionName callback:(CAPPluginCall*)callback {
|
|
125
|
+
if(self._callbacks == nil) {
|
|
126
|
+
self._callbacks = [[NSMutableDictionary alloc]initWithCapacity:1];
|
|
127
|
+
[self._callbacks setObject:callback forKey:functionName];
|
|
128
|
+
} else {
|
|
129
|
+
[self._callbacks setObject:callback forKey:functionName];
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
-(void)onPrinterLibraryEvent:(PrinterLibraryEvent*)event {
|
|
134
|
+
switch([event getEventType]) {
|
|
135
|
+
case SUCCESS:
|
|
136
|
+
[self handleSuccess:event];
|
|
137
|
+
break;
|
|
138
|
+
case FAILED:
|
|
139
|
+
[self handleError:event];
|
|
140
|
+
break;
|
|
141
|
+
case NOTIFY:
|
|
142
|
+
[self handleNotification:event];
|
|
143
|
+
break;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
-(void) activateLicense:(CAPPluginCall*)call {
|
|
148
|
+
if(self._printerlibrary != nil) {
|
|
149
|
+
[call save];
|
|
150
|
+
savedLastCall = call;
|
|
151
|
+
[self._printerlibrary activateLicense:[call.options valueForKey:@"licenseKey"] customerID:[call.options valueForKey:@"customerID"]];
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
@end
|
|
156
|
+
|
|
157
|
+
//-(void) initCIDScannerLib:(CAPPluginCall*)call {
|
|
158
|
+
// NSLog(@"initCaptureID");
|
|
159
|
+
// // get display size
|
|
160
|
+
// CGFloat width = [UIScreen mainScreen].bounds.size.width;
|
|
161
|
+
// CGFloat height = [UIScreen mainScreen].bounds.size.height;
|
|
162
|
+
//
|
|
163
|
+
// // run on main thread to init the UIView
|
|
164
|
+
// dispatch_async(dispatch_get_main_queue(), ^{
|
|
165
|
+
// self.previewView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, width, height)];
|
|
166
|
+
//// [self.previewView setBackgroundColor:[UIColor yellowColor]];
|
|
167
|
+
// self.previewView.alpha = 0.0f;
|
|
168
|
+
// //self.previewView.opaque = NO;
|
|
169
|
+
// //self.previewView.backgroundColor = [UIColor clearColor];
|
|
170
|
+
// UIWindow *currentWindow = [UIApplication sharedApplication].keyWindow;
|
|
171
|
+
// [currentWindow addSubview:self.previewView];
|
|
172
|
+
// self.CPID_decoder = [[CaptureIDLibrary alloc]initWithUIview:self.previewView resultBlock:^(NSArray* result) {
|
|
173
|
+
// [self notifyListeners:@"statusEvent" data:result[0]];
|
|
174
|
+
// }];
|
|
175
|
+
//
|
|
176
|
+
// });
|
|
177
|
+
//
|
|
178
|
+
// package app.captureid.plugins.cidprint;
|
|
179
|
+
//
|
|
180
|
+
// import android.content.Intent;
|
|
181
|
+
// import android.util.Log;
|
|
182
|
+
// import com.getcapacitor.JSObject;
|
|
183
|
+
// import com.getcapacitor.NativePlugin;
|
|
184
|
+
// import com.getcapacitor.Plugin;
|
|
185
|
+
// import com.getcapacitor.PluginCall;
|
|
186
|
+
// import com.getcapacitor.PluginMethod;
|
|
187
|
+
// import com.getcapacitor.PluginResult;
|
|
188
|
+
// import org.json.JSONException;
|
|
189
|
+
// import org.json.JSONObject;
|
|
190
|
+
// import java.util.HashMap;
|
|
191
|
+
// import java.util.Iterator;
|
|
192
|
+
// import androidx.appcompat.app.AppCompatActivity;
|
|
193
|
+
// import app.captureid.cidprinterlibrary.CIDPrinter;
|
|
194
|
+
// import app.captureid.cidprinterlibrary.connectors.BluetoothConnector;
|
|
195
|
+
// import app.captureid.cidprinterlibrary.labels.ReferenceLabel;
|
|
196
|
+
// import app.captureid.cidprinterlibrary.notifications.InitResult;
|
|
197
|
+
// import app.captureid.cidprinterlibrary.notifications.PrinterLibraryEvent;
|
|
198
|
+
// import app.captureid.cidprinterlibrary.notifications.PrinterLibraryListener;
|
|
199
|
+
//
|
|
200
|
+
// @NativePlugin(
|
|
201
|
+
// requestCodes={BluetoothConnector.REQUEST_ENABLE_BT}
|
|
202
|
+
// )
|
|
203
|
+
//
|
|
204
|
+
// public class CIDPrint extends Plugin {
|
|
205
|
+
// private static final String TAG = CIDPrint.class.getSimpleName();
|
|
206
|
+
//
|
|
207
|
+
// private static final String LIBRARY_EVENT = "printerLibraryEvent";
|
|
208
|
+
//
|
|
209
|
+
// private CIDPrinter _printerlibrary;
|
|
210
|
+
// private HashMap<String, PluginCall> _callbacks = new HashMap<String, PluginCall>();
|
|
211
|
+
// private AppCompatActivity _activity;
|
|
212
|
+
// private int _enableBluetoothRequestID;
|
|
213
|
+
//
|
|
214
|
+
// public CIDPrint() {
|
|
215
|
+
// super();
|
|
216
|
+
// }
|
|
217
|
+
//
|
|
218
|
+
// @Override
|
|
219
|
+
// protected void handleOnResume() {
|
|
220
|
+
// super.handleOnResume();
|
|
221
|
+
// _activity = getActivity();
|
|
222
|
+
// }
|
|
223
|
+
//
|
|
224
|
+
// private PrinterLibraryListener _library_listener = new PrinterLibraryListener() {
|
|
225
|
+
// @Override
|
|
226
|
+
// public void onPrinterLibraryEvent(PrinterLibraryEvent event) {
|
|
227
|
+
// switch(event.getEventType()) {
|
|
228
|
+
// case SUCCESS:
|
|
229
|
+
// handleSuccess(event);
|
|
230
|
+
// break;
|
|
231
|
+
// case FAILED:
|
|
232
|
+
// handleError(event);
|
|
233
|
+
// break;
|
|
234
|
+
// case NOTIFY:
|
|
235
|
+
// handleNotification(event);
|
|
236
|
+
// break;
|
|
237
|
+
// }
|
|
238
|
+
// }
|
|
239
|
+
//
|
|
240
|
+
// @Override
|
|
241
|
+
// public void requestForStartIntent(Intent intent, int requestID) {
|
|
242
|
+
// _enableBluetoothRequestID = requestID;
|
|
243
|
+
// startActivityForResult(savedLastCall, intent, requestID);
|
|
244
|
+
// }
|
|
245
|
+
// };
|
|
246
|
+
//
|
|
247
|
+
// private void handleSuccess(PrinterLibraryEvent evt) {
|
|
248
|
+
// JSObject obj = null;
|
|
249
|
+
// try {
|
|
250
|
+
// obj = fromJSONObject(evt.getJSONObject());
|
|
251
|
+
// } catch (JSONException e) {
|
|
252
|
+
// e.printStackTrace();
|
|
253
|
+
// }
|
|
254
|
+
// try {
|
|
255
|
+
// switch(evt.getAction()) {
|
|
256
|
+
// case LICENSE_ACTIVATION:
|
|
257
|
+
// savedLastCall.success(obj);
|
|
258
|
+
// default:
|
|
259
|
+
// notifyListeners(LIBRARY_EVENT, obj);
|
|
260
|
+
// }
|
|
261
|
+
// // switch (evt.getAction()) {
|
|
262
|
+
// // case DISCOVER:
|
|
263
|
+
// // notifyListeners(LIBRARY_EVENT, obj);
|
|
264
|
+
// //// _callbacks.get("discoverDevices").successCallback(result);
|
|
265
|
+
// // break;
|
|
266
|
+
// // case CONNECT:
|
|
267
|
+
// //// _callbacks.get("connectToPreferredPrinter").successCallback(result);
|
|
268
|
+
// // break;
|
|
269
|
+
// // case PRINT:
|
|
270
|
+
// // notifyListeners(LIBRARY_EVENT, obj);
|
|
271
|
+
// // break;
|
|
272
|
+
// // }
|
|
273
|
+
// } catch(Exception ex) {
|
|
274
|
+
// Log.d(TAG, "handleSuccess: " + ex.getMessage());
|
|
275
|
+
// }
|
|
276
|
+
// }
|
|
277
|
+
//
|
|
278
|
+
// private void handleError(PrinterLibraryEvent evt) {
|
|
279
|
+
// JSObject obj = new JSObject();
|
|
280
|
+
// try {
|
|
281
|
+
// obj = fromJSONObject((evt.getJSONObject()));
|
|
282
|
+
// } catch(JSONException ex) {
|
|
283
|
+
// Log.d(TAG, "handleError: " + ex.getMessage());
|
|
284
|
+
// }
|
|
285
|
+
// notifyListeners(LIBRARY_EVENT, obj);
|
|
286
|
+
// }
|
|
287
|
+
//
|
|
288
|
+
// private void handleNotification(PrinterLibraryEvent evt) {
|
|
289
|
+
// JSObject obj = new JSObject();
|
|
290
|
+
// try {
|
|
291
|
+
// obj = fromJSONObject(evt.getJSONObject());
|
|
292
|
+
// } catch (JSONException ex) {
|
|
293
|
+
// Log.d(TAG, "handleNotification: " + ex.getMessage());
|
|
294
|
+
// }
|
|
295
|
+
// notifyListeners(LIBRARY_EVENT, obj);
|
|
296
|
+
// }
|
|
297
|
+
//
|
|
298
|
+
// private void addCallback(String functionName, PluginCall callback) {
|
|
299
|
+
// if(_callbacks.containsKey(functionName)) {
|
|
300
|
+
// if(_callbacks.get(functionName).isReleased()) {
|
|
301
|
+
// _callbacks.remove(functionName);
|
|
302
|
+
// _callbacks.put(functionName, callback);
|
|
303
|
+
// }
|
|
304
|
+
// } else {
|
|
305
|
+
// _callbacks.put(functionName, callback);
|
|
306
|
+
// }
|
|
307
|
+
// }
|
|
308
|
+
//
|
|
309
|
+
// private boolean hasRequiredPermissions(String[] permissions) {
|
|
310
|
+
// for(String permission: permissions) {
|
|
311
|
+
// if(!hasPermission(permission)) {
|
|
312
|
+
// return false;
|
|
313
|
+
// }
|
|
314
|
+
// }
|
|
315
|
+
// return true;
|
|
316
|
+
// }
|
|
317
|
+
//
|
|
318
|
+
// @PluginMethod
|
|
319
|
+
// public void debugPrint(PluginCall call) {
|
|
320
|
+
// _printerlibrary.debugPrint(call.getString("label"));
|
|
321
|
+
// }
|
|
322
|
+
//
|
|
323
|
+
// @PluginMethod
|
|
324
|
+
// public void initCIDPrinterLib(PluginCall call) {
|
|
325
|
+
// _printerlibrary = CIDPrinter.getSharedLibrary(_activity);
|
|
326
|
+
// if(_printerlibrary != null) {
|
|
327
|
+
// _printerlibrary.addListener(_library_listener);
|
|
328
|
+
// }
|
|
329
|
+
// PrinterLibraryEvent evt = _printerlibrary.initialize();
|
|
330
|
+
// if(hasRequiredPermissions(CIDPrinter.getRequiredPermissions())) {
|
|
331
|
+
// try {
|
|
332
|
+
// call.success(fromJSONObject(evt.getJSONObject()));
|
|
333
|
+
// } catch (JSONException e) {
|
|
334
|
+
// call.error("initCIDPrinterLib encountered an error: " + e.getMessage());
|
|
335
|
+
// }
|
|
336
|
+
// return;
|
|
337
|
+
// }
|
|
338
|
+
// evt = new PrinterLibraryEvent(PrinterLibraryEvent.EventType.SUCCESS, PrinterLibraryEvent.LibraryActionType.INITIALIZE, new InitResult(CIDPrinter.getRequiredPermissions()));
|
|
339
|
+
// try {
|
|
340
|
+
// call.success(fromJSONObject(evt.getJSONObject()));
|
|
341
|
+
// } catch (JSONException e) {
|
|
342
|
+
// call.error("initCIDPrinterLib encountered an error: " + e.getMessage());
|
|
343
|
+
// }
|
|
344
|
+
// }
|
|
345
|
+
//
|
|
346
|
+
// @PluginMethod
|
|
347
|
+
// public void closeCIDPrinterLib(PluginCall call) {
|
|
348
|
+
// if(_printerlibrary != null) {
|
|
349
|
+
// _printerlibrary.closeSharedlibrary();
|
|
350
|
+
// }
|
|
351
|
+
// }
|
|
352
|
+
//
|
|
353
|
+
// @PluginMethod
|
|
354
|
+
//
|
|
355
|
+
// @PluginMethod
|
|
356
|
+
// public void enableBluetoothPrinting (PluginCall call) {
|
|
357
|
+
// if(_printerlibrary != null) {
|
|
358
|
+
// saveCall(call);
|
|
359
|
+
// addCallback("enableBluetoothPrinting", call);
|
|
360
|
+
// _printerlibrary.enableBluetoothPrinting(call.getBoolean("enable"));
|
|
361
|
+
// }
|
|
362
|
+
// }
|
|
363
|
+
//
|
|
364
|
+
// @PluginMethod
|
|
365
|
+
// public void getPairedDevices(PluginCall call) {
|
|
366
|
+
// if(_printerlibrary != null) {
|
|
367
|
+
// addCallback("getPairedDevices", call);
|
|
368
|
+
// _printerlibrary.getPairedDevices();
|
|
369
|
+
// }
|
|
370
|
+
// }
|
|
371
|
+
//
|
|
372
|
+
// @PluginMethod
|
|
373
|
+
// public void discoverDevices(PluginCall call) {
|
|
374
|
+
// if(_printerlibrary != null) {
|
|
375
|
+
// addCallback("discoverDevices", call);
|
|
376
|
+
// _printerlibrary.discoverDevices();
|
|
377
|
+
// }
|
|
378
|
+
// }
|
|
379
|
+
//
|
|
380
|
+
// @PluginMethod
|
|
381
|
+
// public void printReferenceLabel(PluginCall call) {
|
|
382
|
+
// if(_printerlibrary != null) {
|
|
383
|
+
// _printerlibrary.printReferenceLabel(ReferenceLabel.ReferenceLabelType.values()[call.getInt("labeltype", 0)]);
|
|
384
|
+
// }
|
|
385
|
+
// }
|
|
386
|
+
//
|
|
387
|
+
// @PluginMethod
|
|
388
|
+
// public void printData(PluginCall call) {
|
|
389
|
+
// if(_printerlibrary != null) {
|
|
390
|
+
// addCallback("printData", call);
|
|
391
|
+
// _printerlibrary.print(call.getString("data").getBytes(), false);
|
|
392
|
+
// }
|
|
393
|
+
// }
|
|
394
|
+
//
|
|
395
|
+
// @PluginMethod
|
|
396
|
+
// public void printNativeData(PluginCall call) {
|
|
397
|
+
// if(_printerlibrary != null) {
|
|
398
|
+
// addCallback("printNativeData", call);
|
|
399
|
+
// _printerlibrary.print(call.getString("data").getBytes(), true);
|
|
400
|
+
// }
|
|
401
|
+
// }
|
|
402
|
+
//
|
|
403
|
+
// @PluginMethod
|
|
404
|
+
// public void printLabelWithObject(PluginCall call) {
|
|
405
|
+
// try {
|
|
406
|
+
// if (_printerlibrary != null) {
|
|
407
|
+
// addCallback("printLabelWithObject", call);
|
|
408
|
+
// _printerlibrary.print(call.getString("label"), call.getData(). getJSONObject("data").getJSONObject("variables"));
|
|
409
|
+
// }
|
|
410
|
+
// } catch(JSONException ex) {
|
|
411
|
+
// Log.d(TAG, "printLabelWithData: " + ex.getMessage());
|
|
412
|
+
// } catch(ClassCastException ex) {
|
|
413
|
+
// Log.d(TAG, "printLabelWithData: " + ex.getMessage());
|
|
414
|
+
// } catch(Exception ex) {
|
|
415
|
+
// Log.d(TAG, "printLabelWithData: " + ex.getMessage());
|
|
416
|
+
// }
|
|
417
|
+
// }
|
|
418
|
+
//
|
|
419
|
+
// @PluginMethod
|
|
420
|
+
// public void printLabelWithData(PluginCall call) {
|
|
421
|
+
// try {
|
|
422
|
+
// if (_printerlibrary != null) {
|
|
423
|
+
// addCallback("printLabelWithData", call);
|
|
424
|
+
// _printerlibrary.print(call.getString("label"), call.getArray("data").toList().toArray(new String[call.getArray("data").toList().size()]));
|
|
425
|
+
// }
|
|
426
|
+
// } catch(JSONException ex) {
|
|
427
|
+
// Log.d(TAG, "printLabelWithData: " + ex.getMessage());
|
|
428
|
+
// } catch(ClassCastException ex) {
|
|
429
|
+
// Log.d(TAG, "printLabelWithData: " + ex.getMessage());
|
|
430
|
+
// } catch(Exception ex) {
|
|
431
|
+
// Log.d(TAG, "printLabelWithData: " + ex.getMessage());
|
|
432
|
+
// }
|
|
433
|
+
// }
|
|
434
|
+
//
|
|
435
|
+
// @PluginMethod
|
|
436
|
+
// public void getPrinterStatus(PluginCall call) {
|
|
437
|
+
// if(_printerlibrary != null) {
|
|
438
|
+
// _printerlibrary.getStatus();
|
|
439
|
+
// }
|
|
440
|
+
// }
|
|
441
|
+
//
|
|
442
|
+
// @PluginMethod
|
|
443
|
+
// public void setupMediaSize(PluginCall call) {
|
|
444
|
+
// if(_printerlibrary != null) {
|
|
445
|
+
// _printerlibrary.setupMediaSize(call.getInt("width"), call.getInt("height"));
|
|
446
|
+
// }
|
|
447
|
+
// }
|
|
448
|
+
//
|
|
449
|
+
// @PluginMethod
|
|
450
|
+
// public void enableDispendingMode(PluginCall call) {
|
|
451
|
+
// if(_printerlibrary != null) {
|
|
452
|
+
// _printerlibrary.enableDispensingMode(call.getBoolean("enable"));
|
|
453
|
+
// }
|
|
454
|
+
// }
|
|
455
|
+
//
|
|
456
|
+
// @PluginMethod
|
|
457
|
+
// public void printLabel(PluginCall call) {
|
|
458
|
+
// if(_printerlibrary != null) {
|
|
459
|
+
// addCallback("printData", call);
|
|
460
|
+
// _printerlibrary.print(call.getString("label"));
|
|
461
|
+
// }
|
|
462
|
+
// }
|
|
463
|
+
//
|
|
464
|
+
// @PluginMethod
|
|
465
|
+
// public void disconnectFromPrinter(PluginCall call) {
|
|
466
|
+
// if(_printerlibrary != null) {
|
|
467
|
+
// _printerlibrary.disconnectPrinter();
|
|
468
|
+
// }
|
|
469
|
+
// }
|
|
470
|
+
|
|
471
|
+
//
|
|
472
|
+
// @Override
|
|
473
|
+
// protected void handleOnActivityResult(int requestCode, int resultCode, Intent data) {
|
|
474
|
+
// super.handleOnActivityResult(requestCode, resultCode, data);
|
|
475
|
+
// if(_printerlibrary != null) {
|
|
476
|
+
// _printerlibrary.handleOnActivityResult(requestCode, resultCode, data);
|
|
477
|
+
// }
|
|
478
|
+
// }
|
|
479
|
+
//
|
|
480
|
+
// @Override
|
|
481
|
+
// protected void handleOnRestart() {
|
|
482
|
+
// super.handleOnRestart();
|
|
483
|
+
// if(_printerlibrary != null) {
|
|
484
|
+
// _printerlibrary.onResume();
|
|
485
|
+
// }
|
|
486
|
+
// }
|
|
487
|
+
//
|
|
488
|
+
// @Override
|
|
489
|
+
// protected void handleOnPause() {
|
|
490
|
+
// if(_printerlibrary != null) {
|
|
491
|
+
// _printerlibrary.onPause();
|
|
492
|
+
// }
|
|
493
|
+
// super.handleOnPause();
|
|
494
|
+
// }
|
|
495
|
+
//
|
|
496
|
+
// @Override
|
|
497
|
+
// protected void handleOnDestroy() {
|
|
498
|
+
// if(_printerlibrary != null) {
|
|
499
|
+
// _printerlibrary.onDestroy();
|
|
500
|
+
// }
|
|
501
|
+
// super.handleOnDestroy();
|
|
502
|
+
// }
|
|
503
|
+
//
|
|
504
|
+
// private JSObject fromJSONObject(JSONObject jobj) throws JSONException {
|
|
505
|
+
// Iterator<String> keys = jobj.keys();
|
|
506
|
+
// while(keys.hasNext()) {
|
|
507
|
+
// String key = keys.next();
|
|
508
|
+
// try {
|
|
509
|
+
// if(jobj.get(key) instanceof JSONObject) {
|
|
510
|
+
// jobj.put(key, fromJSONObject((JSONObject) jobj.get(key)));
|
|
511
|
+
// }
|
|
512
|
+
// } catch (JSONException e) {
|
|
513
|
+
// Log.d(TAG, "fromJSONObject encounters an error in " + key + " error: " + e.getMessage());
|
|
514
|
+
// }
|
|
515
|
+
// }
|
|
516
|
+
// return JSObject.fromJSONObject(jobj);
|
|
517
|
+
// }
|
|
518
|
+
// }
|
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
//
|
|
2
|
+
// CIDPrintPlugin.h
|
|
3
|
+
// Pods
|
|
4
|
+
//
|
|
5
|
+
// Created by Uwe Hoppe on 17.11.21.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
#ifndef CIDPrintPlugin_h
|
|
9
|
+
#define CIDPrintPlugin_h
|
|
10
|
+
|
|
1
11
|
#import <UIKit/UIKit.h>
|
|
2
12
|
|
|
3
13
|
//! Project version number for Plugin.
|
|
@@ -6,5 +16,4 @@ FOUNDATION_EXPORT double PluginVersionNumber;
|
|
|
6
16
|
//! Project version string for Plugin.
|
|
7
17
|
FOUNDATION_EXPORT const unsigned char PluginVersionString[];
|
|
8
18
|
|
|
9
|
-
|
|
10
|
-
|
|
19
|
+
#endif /* CIDPrintPlugin_h */
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
//
|
|
2
|
+
// CIDPrintPlugin.m
|
|
3
|
+
// CaptureidCapacitorCidprint
|
|
4
|
+
//
|
|
5
|
+
// Created by Uwe Hoppe on 17.11.21.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
#import <Foundation/Foundation.h>
|
|
9
|
+
#import <Capacitor/Capacitor.h>
|
|
10
|
+
|
|
11
|
+
CAP_PLUGIN(CIDPrint, "CIDPrint",
|
|
12
|
+
CAP_PLUGIN_METHOD(initCIDPrinterLib, CAPPluginReturnPromise);
|
|
13
|
+
CAP_PLUGIN_METHOD(closeCIDPrinterLib, CAPPluginReturnPromise);
|
|
14
|
+
CAP_PLUGIN_METHOD(activateLicense, CAPPluginReturnPromise);
|
|
15
|
+
CAP_PLUGIN_METHOD(enableBluetoothPrinting, CAPPluginReturnPromise);
|
|
16
|
+
CAP_PLUGIN_METHOD(getPairedDevices, CAPPluginReturnPromise);
|
|
17
|
+
CAP_PLUGIN_METHOD(discoverDevices, CAPPluginReturnPromise);
|
|
18
|
+
CAP_PLUGIN_METHOD(printReferenceLabel, CAPPluginReturnPromise);
|
|
19
|
+
CAP_PLUGIN_METHOD(printData, CAPPluginReturnPromise);
|
|
20
|
+
CAP_PLUGIN_METHOD(printNativeData, CAPPluginReturnPromise);
|
|
21
|
+
CAP_PLUGIN_METHOD(printLabelWithObject, CAPPluginReturnPromise);
|
|
22
|
+
CAP_PLUGIN_METHOD(printReceiptWithObject, CAPPluginReturnPromise);
|
|
23
|
+
CAP_PLUGIN_METHOD(printLabelWithData, CAPPluginReturnPromise);
|
|
24
|
+
CAP_PLUGIN_METHOD(getPrinterStatus, CAPPluginReturnPromise);
|
|
25
|
+
CAP_PLUGIN_METHOD(setupMediaSize, CAPPluginReturnPromise);
|
|
26
|
+
CAP_PLUGIN_METHOD(enableDispendingMode, CAPPluginReturnPromise);
|
|
27
|
+
CAP_PLUGIN_METHOD(printLabel, CAPPluginReturnPromise);
|
|
28
|
+
CAP_PLUGIN_METHOD(disconnectFromPrinter, CAPPluginReturnPromise);
|
|
29
|
+
CAP_PLUGIN_METHOD(connectToPreferredPrinter, CAPPluginReturnPromise);
|
|
30
|
+
)
|
|
31
|
+
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
//
|
|
2
|
+
// CIDPrinter.h
|
|
3
|
+
// CIDPrinterLibrary
|
|
4
|
+
//
|
|
5
|
+
// Created by Uwe Hoppe on 17.11.21.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
#ifndef CIDPrinter_h
|
|
9
|
+
#define CIDPrinter_h
|
|
10
|
+
#import "PrinterLibraryEvent.h"
|
|
11
|
+
#import "Device.h"
|
|
12
|
+
|
|
13
|
+
@interface CIDPrinter: NSObject <PrinterLibraryListener>
|
|
14
|
+
@property id<PrinterLibraryListener> _listener;
|
|
15
|
+
|
|
16
|
+
+(CIDPrinter*) getSharedObject;
|
|
17
|
+
+(NSArray<NSString*>*) getRequiredPermissions;
|
|
18
|
+
|
|
19
|
+
-(PrinterLibraryEvent*) initialize;
|
|
20
|
+
-(void) closeSharedlibrary;
|
|
21
|
+
-(NSUInteger) activatePluginLicense:(NSString*)key customer:(NSString*)customer;
|
|
22
|
+
-(void) activateLicense:(NSString*)licenseKey customerID:(NSString*)customerID;
|
|
23
|
+
-(void) addListener:(id<PrinterLibraryListener>)listener;
|
|
24
|
+
-(void) removeListener:(id<PrinterLibraryListener>)listener;
|
|
25
|
+
-(void) enableBluetoothPrinting:(BOOL)enable;
|
|
26
|
+
-(NSDictionary<NSString*, Device*>*) getPairedDevices;
|
|
27
|
+
-(void) discoverDevices;
|
|
28
|
+
-(void) notifyListeners:(PrinterLibraryEvent*)evt;
|
|
29
|
+
-(void) connectToPreferredPrinter:(NSString*)address;
|
|
30
|
+
-(void) disconnectPrinter;
|
|
31
|
+
-(void) getStatus;
|
|
32
|
+
-(void) enableDispensingMode:(BOOL)enable;
|
|
33
|
+
-(void) setupMediaSize:(NSUInteger)width height:(NSUInteger)height;
|
|
34
|
+
-(void) print:(NSData*)data isnative:(BOOL)_isnative;
|
|
35
|
+
-(void) debugPrint:(NSString*)labelfile;
|
|
36
|
+
-(void) print:(NSString*)labelfile;
|
|
37
|
+
-(void) print:(NSString*)labelfile params:(NSDictionary*)params;
|
|
38
|
+
-(void) printReceipt:(NSString*)labelfile params:(NSDictionary*)params;
|
|
39
|
+
-(void) print:(NSString*)labelfile strings:(NSArray*)params;
|
|
40
|
+
|
|
41
|
+
@end
|
|
42
|
+
|
|
43
|
+
#endif /* CIDPrinter_h */
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Device.h
|
|
3
|
+
// CIDPrinterLibrary
|
|
4
|
+
//
|
|
5
|
+
// Created by Uwe Hoppe on 18.11.21.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
#ifndef Device_h
|
|
9
|
+
#define Device_h
|
|
10
|
+
|
|
11
|
+
#import "BluetoothManager.h"
|
|
12
|
+
|
|
13
|
+
extern NSString * const cDeviceDidConnect;
|
|
14
|
+
extern NSString * const cDeviceDidDisconnect;
|
|
15
|
+
extern NSString * const cDeviceConnectionErrorDomain;
|
|
16
|
+
extern const NSInteger cConnectionTimeoutErrorCode;
|
|
17
|
+
extern const NSInteger cConnectionMissingErrorCode;
|
|
18
|
+
extern NSString * const cConnectionTimeoutErrorMessage;
|
|
19
|
+
extern NSString * const cConnectionMissingErrorMessage;
|
|
20
|
+
|
|
21
|
+
typedef void(^DeviceConnectionCallback)(NSError *error);
|
|
22
|
+
typedef void(^DeviceDiscoverServicesCallback)(NSArray *services, NSError *error);
|
|
23
|
+
typedef void(^DeviceRSSIValueCallback)(NSNumber *RSSI, NSError *error);
|
|
24
|
+
|
|
25
|
+
@import CoreBluetooth;
|
|
26
|
+
|
|
27
|
+
@interface Device : NSObject
|
|
28
|
+
|
|
29
|
+
@property (weak, nonatomic, getter = uuid) NSString *uuid;
|
|
30
|
+
@property (weak, nonatomic, getter = getName) NSString *devicename;
|
|
31
|
+
@property (weak, nonatomic, readonly) NSString *address;
|
|
32
|
+
@property (assign, nonatomic) NSInteger rssi;
|
|
33
|
+
@property (strong, nonatomic) NSDictionary *data;
|
|
34
|
+
@property (strong, nonatomic, readonly) CBPeripheral *peripheral;
|
|
35
|
+
@property (strong, nonatomic, readonly) BluetoothManager *manager;
|
|
36
|
+
@property (assign, nonatomic) BOOL discoveringservices;
|
|
37
|
+
|
|
38
|
+
@property (assign, nonatomic, readonly) BOOL watchDogRaised;
|
|
39
|
+
@property (assign, nonatomic, readonly, getter = isDiscoveringServices) BOOL discoveringServices;
|
|
40
|
+
@property (strong, nonatomic, readonly) NSArray *services;
|
|
41
|
+
@property (strong, nonatomic) NSDictionary *advertisingData;
|
|
42
|
+
|
|
43
|
+
- (void)connectWithCallback:(DeviceConnectionCallback)callback;
|
|
44
|
+
- (void)connectWithTimeout:(NSUInteger)aWatchDogInterval callback:(DeviceConnectionCallback)callback;
|
|
45
|
+
- (void)disconnectWithCallback:(DeviceConnectionCallback)callback;
|
|
46
|
+
- (void)discoverServicesWithCallback:(DeviceDiscoverServicesCallback)callback;
|
|
47
|
+
- (void)discoverServices:(NSArray *)serviceUUIDs callback:(DeviceDiscoverServicesCallback)callback;
|
|
48
|
+
- (void)readRSSIValueCallback:(DeviceRSSIValueCallback)callback;
|
|
49
|
+
- (void)handleConnectWithError:(NSError *)error;
|
|
50
|
+
- (void)handleDisconnectWithError:(NSError *)error;
|
|
51
|
+
|
|
52
|
+
-(id) initWithPeripheral:(CBPeripheral*)peripheral manager:(BluetoothManager*)manager;
|
|
53
|
+
-(NSDictionary*) getJSONObject;
|
|
54
|
+
|
|
55
|
+
@end
|
|
56
|
+
|
|
57
|
+
#endif /* Device_h */
|
package/ios/Plugin/Info.plist
CHANGED
|
@@ -18,6 +18,14 @@
|
|
|
18
18
|
<string>1.0</string>
|
|
19
19
|
<key>CFBundleVersion</key>
|
|
20
20
|
<string>$(CURRENT_PROJECT_VERSION)</string>
|
|
21
|
+
<key>NSBluetoothAlwaysUsageDescription</key>
|
|
22
|
+
<string>We need bluetooth connection to print receipts</string>
|
|
23
|
+
<key>NSBluetoothPeripheralUsageDescription</key>
|
|
24
|
+
<string>We need bluetooth connection to print receipts</string>
|
|
25
|
+
<key>UIBackgroundModes</key>
|
|
26
|
+
<array>
|
|
27
|
+
<string>bluetooth-central</string>
|
|
28
|
+
</array>
|
|
21
29
|
<key>NSPrincipalClass</key>
|
|
22
30
|
<string></string>
|
|
23
31
|
</dict>
|