cordova-plugin-mserviceinterface-2.0 1.0.80 → 1.0.82

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cordova-plugin-mserviceinterface-2.0",
3
- "version": "1.0.80",
3
+ "version": "1.0.82",
4
4
  "description": "This plugin establishes the connection to the native interface and performs the requested task.",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/plugin.xml CHANGED
@@ -1,6 +1,6 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
2
  <plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
3
- xmlns:android="http://schemas.android.com/apk/res/android" id="cordova-plugin-mserviceinterface-2.0" version="1.0.80">
3
+ xmlns:android="http://schemas.android.com/apk/res/android" id="cordova-plugin-mserviceinterface-2.0" version="1.0.82">
4
4
  <name>mserviceinterface-2.0</name>
5
5
  <description>This plugin establishes the connection to the native interface and performs the requested task.</description>
6
6
  <author>selfservit@gmail.com</author>
@@ -9,6 +9,7 @@
9
9
  #import <QuickLook/QuickLook.h>
10
10
  #import "SSZipArchive.h"
11
11
  #import <MessageUI/MessageUI.h>
12
+ #import <AVFoundation/AVFoundation.h>
12
13
  @interface mInterface : CDVPlugin <CLLocationManagerDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate, UIAlertViewDelegate, QLPreviewControllerDelegate, QLPreviewControllerDataSource, QLPreviewItem, SSZipArchiveDelegate, UIDocumentInteractionControllerDelegate, MFMessageComposeViewControllerDelegate>
13
14
  {
14
15
  #define FILE_EXTENSION @".png"
@@ -42,6 +43,8 @@
42
43
  UIInterfaceOrientation _lastOrientation;
43
44
  }
44
45
  @property(strong) NSString* callbackID;
46
+ - (void)ScanBarCode:(CDVInvokedUrlCommand*)command;
47
+ - (void)ScanQRCode:(CDVInvokedUrlCommand*)command;
45
48
  - (void)viewRoute:(CDVInvokedUrlCommand*)command;
46
49
  - (void)GetFCMUtils:(CDVInvokedUrlCommand *)command;
47
50
  -(void)GetBase64String:(CDVInvokedUrlCommand *)command;
@@ -131,4 +134,5 @@
131
134
  @property(readonly) NSURL *previewItemURL;
132
135
  @property (nonatomic, copy) NSString* fileOpenCallbackId;
133
136
  @property(nonatomic, strong) UIDocumentInteractionController *controller;
137
+ @property (strong, nonatomic) AVCaptureSession *captureSession;
134
138
  @end
@@ -13,7 +13,7 @@
13
13
  #import "OneSignalPush.h"
14
14
  #import <OneSignal/OneSignal.h>
15
15
  #import <objc/runtime.h>
16
-
16
+ #import <AVFoundation/AVFoundation.h>
17
17
  #if defined(__IPHONE_10_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
18
18
  @import UserNotifications;
19
19
  #endif
@@ -29,6 +29,159 @@
29
29
  @synthesize controller = docController;
30
30
  @synthesize callbackID;
31
31
 
32
+
33
+
34
+ // Inside the @implementation block
35
+ - (void)ScanBarCode:(CDVInvokedUrlCommand*)command {
36
+ self.callbackID = command.callbackId;
37
+
38
+ // Initialize the AVCaptureSession
39
+ self.captureSession = [[AVCaptureSession alloc] init];
40
+ AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
41
+
42
+ NSError *error = nil;
43
+ AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error:&error];
44
+
45
+ if (!input) {
46
+ CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:[error localizedDescription]];
47
+ [self.commandDelegate sendPluginResult:result callbackId:self.callbackID];
48
+ return;
49
+ }
50
+
51
+ [self.captureSession addInput:input];
52
+
53
+ AVCaptureMetadataOutput *output = [[AVCaptureMetadataOutput alloc] init];
54
+ [self.captureSession addOutput:output];
55
+
56
+ // Support both QR codes and barcodes
57
+ NSArray *supportedTypes = @[AVMetadataObjectTypeQRCode,
58
+ AVMetadataObjectTypeEAN13Code,
59
+ AVMetadataObjectTypeEAN8Code,
60
+ AVMetadataObjectTypeCode128Code,
61
+ AVMetadataObjectTypeUPCECode];
62
+
63
+ [output setMetadataObjectTypes:supportedTypes];
64
+ [output setMetadataObjectsDelegate:self queue:dispatch_get_main_queue()];
65
+
66
+ // Add the video preview layer
67
+ dispatch_async(dispatch_get_main_queue(), ^{
68
+ AVCaptureVideoPreviewLayer *previewLayer = [AVCaptureVideoPreviewLayer layerWithSession:self.captureSession];
69
+ previewLayer.frame = self.viewController.view.bounds;
70
+ previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
71
+
72
+ // Retain reference to the layer
73
+ objc_setAssociatedObject(self, @selector(previewLayer), previewLayer, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
74
+ [self.viewController.view.layer addSublayer:previewLayer];
75
+
76
+ // Add an "X" close button
77
+ UIButton *closeButton = [UIButton buttonWithType:UIButtonTypeSystem];
78
+ closeButton.frame = CGRectMake(self.viewController.view.frame.size.width - 50, 50, 40, 40); // Position: Top-right corner
79
+ [closeButton setTitle:@"✕" forState:UIControlStateNormal]; // Unicode "X"
80
+ closeButton.titleLabel.font = [UIFont boldSystemFontOfSize:24];
81
+ [closeButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
82
+ closeButton.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.7];
83
+ closeButton.layer.cornerRadius = 20;
84
+ closeButton.clipsToBounds = YES;
85
+ [closeButton addTarget:self action:@selector(closeScanner) forControlEvents:UIControlEventTouchUpInside];
86
+
87
+ [self.viewController.view addSubview:closeButton];
88
+ objc_setAssociatedObject(self, @selector(closeScanner), closeButton, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
89
+ });
90
+
91
+ // Start scanning on a background thread
92
+ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
93
+ [self.captureSession startRunning];
94
+ });
95
+ }
96
+ - (void)closeScanner {
97
+ // Stop the capture session
98
+ [self.captureSession stopRunning];
99
+
100
+ // Remove the preview layer and close button
101
+ dispatch_async(dispatch_get_main_queue(), ^{
102
+ AVCaptureVideoPreviewLayer *previewLayer = objc_getAssociatedObject(self, @selector(previewLayer));
103
+ [previewLayer removeFromSuperlayer];
104
+
105
+ UIButton *closeButton = objc_getAssociatedObject(self, @selector(closeScanner));
106
+ [closeButton removeFromSuperview];
107
+ });
108
+
109
+ // Notify JavaScript that scanning was cancelled
110
+ CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Scanning cancelled"];
111
+ [self.commandDelegate sendPluginResult:result callbackId:self.callbackID];
112
+ }
113
+ - (void)ScanQRCode:(CDVInvokedUrlCommand*)command {
114
+ self.callbackID = command.callbackId;
115
+
116
+ // Initialize the AVCaptureSession
117
+ self.captureSession = [[AVCaptureSession alloc] init];
118
+ AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
119
+
120
+ NSError *error = nil;
121
+ AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error:&error];
122
+
123
+ if (!input) {
124
+ CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:[error localizedDescription]];
125
+ [self.commandDelegate sendPluginResult:result callbackId:self.callbackID];
126
+ return;
127
+ }
128
+
129
+ [self.captureSession addInput:input];
130
+
131
+ AVCaptureMetadataOutput *output = [[AVCaptureMetadataOutput alloc] init];
132
+ [self.captureSession addOutput:output];
133
+
134
+ [output setMetadataObjectTypes:@[AVMetadataObjectTypeQRCode, AVMetadataObjectTypeEAN13Code]];
135
+ [output setMetadataObjectsDelegate:self queue:dispatch_get_main_queue()];
136
+
137
+ // Add the video preview layer
138
+ dispatch_async(dispatch_get_main_queue(), ^{
139
+ AVCaptureVideoPreviewLayer *previewLayer = [AVCaptureVideoPreviewLayer layerWithSession:self.captureSession];
140
+ previewLayer.frame = self.viewController.view.bounds;
141
+ previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
142
+
143
+ // Retain reference to the layer
144
+ objc_setAssociatedObject(self, @selector(previewLayer), previewLayer, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
145
+ [self.viewController.view.layer addSublayer:previewLayer];
146
+ // Add an "X" close button
147
+ UIButton *closeButton = [UIButton buttonWithType:UIButtonTypeSystem];
148
+ closeButton.frame = CGRectMake(self.viewController.view.frame.size.width - 50, 50, 40, 40); // Position: Top-right corner
149
+ [closeButton setTitle:@"✕" forState:UIControlStateNormal]; // Unicode "X"
150
+ closeButton.titleLabel.font = [UIFont boldSystemFontOfSize:24];
151
+ [closeButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
152
+ closeButton.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.7];
153
+ closeButton.layer.cornerRadius = 20;
154
+ closeButton.clipsToBounds = YES;
155
+ [closeButton addTarget:self action:@selector(closeScanner) forControlEvents:UIControlEventTouchUpInside];
156
+
157
+ [self.viewController.view addSubview:closeButton];
158
+ objc_setAssociatedObject(self, @selector(closeScanner), closeButton, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
159
+ });
160
+
161
+ // Start scanning on a background thread
162
+ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
163
+ [self.captureSession startRunning];
164
+ });
165
+ }
166
+
167
+ - (void)captureOutput:(AVCaptureOutput *)output didOutputMetadataObjects:(NSArray<__kindof AVMetadataObject *> *)metadataObjects fromConnection:(AVCaptureConnection *)connection {
168
+ if (metadataObjects.count > 0) {
169
+ [self.captureSession stopRunning];
170
+
171
+ AVMetadataMachineReadableCodeObject *metadataObj = metadataObjects.firstObject;
172
+ NSString *scannedCode = metadataObj.stringValue;
173
+
174
+ // Remove the preview layer on the main thread
175
+ dispatch_async(dispatch_get_main_queue(), ^{
176
+ AVCaptureVideoPreviewLayer *previewLayer = objc_getAssociatedObject(self, @selector(previewLayer));
177
+ [previewLayer removeFromSuperlayer];
178
+ });
179
+
180
+ CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:scannedCode];
181
+ [self.commandDelegate sendPluginResult:result callbackId:self.callbackID];
182
+ }
183
+ }
184
+
32
185
  - (void)viewRoute:(CDVInvokedUrlCommand*)command {
33
186
  CDVPluginResult* pluginResult = nil;
34
187