capacitor-camera-module 0.0.49 → 0.0.51

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.
@@ -7,6 +7,27 @@ import Photos
7
7
  @objc(CameraModule)
8
8
  public class CameraModulePlugin: CAPPlugin,CAPBridgedPlugin,AVCaptureVideoDataOutputSampleBufferDelegate {
9
9
 
10
+
11
+ public let identifier = "CameraModule"
12
+ public let jsName = "CameraModule"
13
+ public let pluginMethods: [CAPPluginMethod] = [
14
+ CAPPluginMethod(name: "checkPermission", returnType: CAPPluginReturnPromise),
15
+ CAPPluginMethod(name: "requestPermission", returnType: CAPPluginReturnPromise),
16
+ CAPPluginMethod(name: "checkGalleryPermission", returnType: CAPPluginReturnPromise),
17
+ CAPPluginMethod(name: "requestGalleryPermission", returnType: CAPPluginReturnPromise),
18
+ CAPPluginMethod(name: "checkAndRequestGalleryPermission", returnType: CAPPluginReturnPromise),
19
+ CAPPluginMethod(name: "pickImageBase64", returnType: CAPPluginReturnPromise),
20
+ CAPPluginMethod(name: "startPreview", returnType: CAPPluginReturnPromise),
21
+ CAPPluginMethod(name: "stopPreview", returnType: CAPPluginReturnPromise),
22
+ CAPPluginMethod(name: "toggleFlash", returnType: CAPPluginReturnPromise),
23
+ CAPPluginMethod(name: "hasFlash", returnType: CAPPluginReturnPromise),
24
+ CAPPluginMethod(name: "takePhotoBase64", returnType: CAPPluginReturnPromise),
25
+ CAPPluginMethod(name: "startBarcodeScan", returnType: CAPPluginReturnPromise),
26
+ CAPPluginMethod(name: "stopBarcodeScan", returnType: CAPPluginReturnPromise)
27
+
28
+ ]
29
+
30
+
10
31
  private var previewView: UIView?
11
32
  private var captureSession: AVCaptureSession?
12
33
  private var videoPreviewLayer: AVCaptureVideoPreviewLayer?
@@ -27,30 +48,6 @@ public class CameraModulePlugin: CAPPlugin,CAPBridgedPlugin,AVCaptureVideoDataOu
27
48
 
28
49
  private var galleryCall: CAPPluginCall?
29
50
 
30
- // MARK: - Capacitor Bridge
31
-
32
- public static let identifier = "CameraModule"
33
- public static let jsName = "CameraModule"
34
- public let pluginMethods: [CAPPluginMethod] = [
35
- CAPPluginMethod(name: "checkPermission", returnType: CAPPluginReturnPromise),
36
- CAPPluginMethod(name: "requestPermission", returnType: CAPPluginReturnPromise),
37
- CAPPluginMethod(name: "checkGalleryPermission", returnType: CAPPluginReturnPromise),
38
- CAPPluginMethod(name: "requestGalleryPermission", returnType: CAPPluginReturnPromise),
39
- CAPPluginMethod(name: "checkAndRequestGalleryPermission", returnType: CAPPluginReturnPromise),
40
- CAPPluginMethod(name: "pickImageBase64", returnType: CAPPluginReturnPromise),
41
- CAPPluginMethod(name: "startPreview", returnType: CAPPluginReturnPromise),
42
- CAPPluginMethod(name: "stopPreview", returnType: CAPPluginReturnPromise),
43
- CAPPluginMethod(name: "toggleFlash", returnType: CAPPluginReturnPromise),
44
- CAPPluginMethod(name: "hasFlash", returnType: CAPPluginReturnPromise),
45
- CAPPluginMethod(name: "takePhotoBase64", returnType: CAPPluginReturnPromise),
46
- CAPPluginMethod(name: "startBarcodeScan", returnType: CAPPluginReturnPromise),
47
- CAPPluginMethod(name: "stopBarcodeScan", returnType: CAPPluginReturnPromise)
48
-
49
- ]
50
-
51
-
52
-
53
-
54
51
  // MARK: - Lifecycle
55
52
 
56
53
  public override func load() {
@@ -229,6 +226,52 @@ public class CameraModulePlugin: CAPPlugin,CAPBridgedPlugin,AVCaptureVideoDataOu
229
226
  ])
230
227
  }
231
228
 
229
+ @objc func getLastGalleryImage(_ call: CAPPluginCall) {
230
+
231
+ let status = PHPhotoLibrary.authorizationStatus(for: .readWrite)
232
+
233
+ guard status == .authorized || status == .limited else {
234
+ call.reject("Gallery permission not granted")
235
+ return
236
+ }
237
+
238
+ let fetchOptions = PHFetchOptions()
239
+ fetchOptions.sortDescriptors = [
240
+ NSSortDescriptor(key: "creationDate", ascending: false)
241
+ ]
242
+ fetchOptions.fetchLimit = 1
243
+
244
+ let assets = PHAsset.fetchAssets(with: .image, options: fetchOptions)
245
+
246
+ guard let asset = assets.firstObject else {
247
+ call.reject("No images found")
248
+ return
249
+ }
250
+
251
+ let imageManager = PHImageManager.default()
252
+ let options = PHImageRequestOptions()
253
+ options.isSynchronous = true
254
+ options.deliveryMode = .highQualityFormat
255
+ options.resizeMode = .none
256
+
257
+ imageManager.requestImageDataAndOrientation(
258
+ for: asset,
259
+ options: options
260
+ ) { data, _, _, _ in
261
+
262
+ guard let imageData = data else {
263
+ call.reject("Error fetching last image")
264
+ return
265
+ }
266
+
267
+ let base64 = imageData.base64EncodedString()
268
+
269
+ let ret = JSObject()
270
+ ret["base64"] = base64
271
+ call.resolve(ret)
272
+ }
273
+ }
274
+
232
275
  // MARK: - Photo Capture
233
276
 
234
277
  @objc func takePhotoBase64(_ call: CAPPluginCall) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "capacitor-camera-module",
3
- "version": "0.0.49",
3
+ "version": "0.0.51",
4
4
  "description": "Plugin to request permissiones view camera take phots",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",