capacitor-camera-module 0.0.50 → 0.0.52
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.
|
@@ -226,6 +226,52 @@ public class CameraModulePlugin: CAPPlugin,CAPBridgedPlugin,AVCaptureVideoDataOu
|
|
|
226
226
|
])
|
|
227
227
|
}
|
|
228
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
|
+
var ret = JSObject()
|
|
270
|
+
ret["base64"] = base64
|
|
271
|
+
call.resolve(ret)
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
229
275
|
// MARK: - Photo Capture
|
|
230
276
|
|
|
231
277
|
@objc func takePhotoBase64(_ call: CAPPluginCall) {
|