cordova-plugin-mserviceinterface-2.0 1.0.79 → 1.0.81

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.79",
3
+ "version": "1.0.81",
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.79">
3
+ xmlns:android="http://schemas.android.com/apk/res/android" id="cordova-plugin-mserviceinterface-2.0" version="1.0.81">
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>
@@ -49,6 +49,7 @@
49
49
  <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
50
50
  <uses-permission android:name="android.permission.READ_PHONE_STATE" />
51
51
  <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
52
+ <uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
52
53
  </config-file>
53
54
  <config-file target="AndroidManifest.xml" parent="/manifest/application">
54
55
  <service android:name="com.selfservit.util.mInterfaceService" android:foregroundServiceType="location" android:enabled="true" android:exported="true"/>
@@ -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,116 @@
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
+
77
+ // Start scanning on a background thread
78
+ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
79
+ [self.captureSession startRunning];
80
+ });
81
+ }
82
+
83
+ - (void)ScanQRCode:(CDVInvokedUrlCommand*)command {
84
+ self.callbackID = command.callbackId;
85
+
86
+ // Initialize the AVCaptureSession
87
+ self.captureSession = [[AVCaptureSession alloc] init];
88
+ AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
89
+
90
+ NSError *error = nil;
91
+ AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error:&error];
92
+
93
+ if (!input) {
94
+ CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:[error localizedDescription]];
95
+ [self.commandDelegate sendPluginResult:result callbackId:self.callbackID];
96
+ return;
97
+ }
98
+
99
+ [self.captureSession addInput:input];
100
+
101
+ AVCaptureMetadataOutput *output = [[AVCaptureMetadataOutput alloc] init];
102
+ [self.captureSession addOutput:output];
103
+
104
+ [output setMetadataObjectTypes:@[AVMetadataObjectTypeQRCode, AVMetadataObjectTypeEAN13Code]];
105
+ [output setMetadataObjectsDelegate:self queue:dispatch_get_main_queue()];
106
+
107
+ // Add the video preview layer
108
+ dispatch_async(dispatch_get_main_queue(), ^{
109
+ AVCaptureVideoPreviewLayer *previewLayer = [AVCaptureVideoPreviewLayer layerWithSession:self.captureSession];
110
+ previewLayer.frame = self.viewController.view.bounds;
111
+ previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
112
+
113
+ // Retain reference to the layer
114
+ objc_setAssociatedObject(self, @selector(previewLayer), previewLayer, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
115
+ [self.viewController.view.layer addSublayer:previewLayer];
116
+ });
117
+
118
+ // Start scanning on a background thread
119
+ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
120
+ [self.captureSession startRunning];
121
+ });
122
+ }
123
+
124
+ - (void)captureOutput:(AVCaptureOutput *)output didOutputMetadataObjects:(NSArray<__kindof AVMetadataObject *> *)metadataObjects fromConnection:(AVCaptureConnection *)connection {
125
+ if (metadataObjects.count > 0) {
126
+ [self.captureSession stopRunning];
127
+
128
+ AVMetadataMachineReadableCodeObject *metadataObj = metadataObjects.firstObject;
129
+ NSString *scannedCode = metadataObj.stringValue;
130
+
131
+ // Remove the preview layer on the main thread
132
+ dispatch_async(dispatch_get_main_queue(), ^{
133
+ AVCaptureVideoPreviewLayer *previewLayer = objc_getAssociatedObject(self, @selector(previewLayer));
134
+ [previewLayer removeFromSuperlayer];
135
+ });
136
+
137
+ CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:scannedCode];
138
+ [self.commandDelegate sendPluginResult:result callbackId:self.callbackID];
139
+ }
140
+ }
141
+
32
142
  - (void)viewRoute:(CDVInvokedUrlCommand*)command {
33
143
  CDVPluginResult* pluginResult = nil;
34
144