@capacitor/camera 1.0.5 → 1.2.0
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/CHANGELOG.md +50 -0
- package/README.md +64 -13
- package/android/src/main/java/com/capacitorjs/plugins/camera/CameraPlugin.java +127 -11
- package/dist/docs.json +212 -3
- package/dist/esm/definitions.d.ts +106 -0
- package/dist/esm/definitions.js +9 -0
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/web.d.ts +3 -1
- package/dist/esm/web.js +47 -0
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +56 -0
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +57 -1
- package/dist/plugin.js.map +1 -1
- package/ios/Plugin/CameraPlugin.m +1 -0
- package/ios/Plugin/CameraPlugin.swift +120 -26
- package/ios/Plugin/CameraTypes.swift +1 -0
- package/ios/Plugin/ImageSaver.swift +20 -0
- package/package.json +4 -5
package/dist/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sources":["esm/definitions.js","esm/index.js","esm/web.js"],"sourcesContent":["export var CameraSource;\n(function (CameraSource) {\n CameraSource[\"Prompt\"] = \"PROMPT\";\n CameraSource[\"Camera\"] = \"CAMERA\";\n CameraSource[\"Photos\"] = \"PHOTOS\";\n})(CameraSource || (CameraSource = {}));\nexport var CameraDirection;\n(function (CameraDirection) {\n CameraDirection[\"Rear\"] = \"REAR\";\n CameraDirection[\"Front\"] = \"FRONT\";\n})(CameraDirection || (CameraDirection = {}));\nexport var CameraResultType;\n(function (CameraResultType) {\n CameraResultType[\"Uri\"] = \"uri\";\n CameraResultType[\"Base64\"] = \"base64\";\n CameraResultType[\"DataUrl\"] = \"dataUrl\";\n})(CameraResultType || (CameraResultType = {}));\n//# sourceMappingURL=definitions.js.map","import { registerPlugin } from '@capacitor/core';\nconst Camera = registerPlugin('Camera', {\n web: () => import('./web').then(m => new m.CameraWeb()),\n});\nexport * from './definitions';\nexport { Camera };\n//# sourceMappingURL=index.js.map","import { WebPlugin, CapacitorException } from '@capacitor/core';\nimport { CameraSource, CameraDirection } from './definitions';\nexport class CameraWeb extends WebPlugin {\n async getPhoto(options) {\n // eslint-disable-next-line no-async-promise-executor\n return new Promise(async (resolve, reject) => {\n if (options.webUseInput || options.source === CameraSource.Photos) {\n this.fileInputExperience(options, resolve);\n }\n else if (options.source === CameraSource.Prompt) {\n let actionSheet = document.querySelector('pwa-action-sheet');\n if (!actionSheet) {\n actionSheet = document.createElement('pwa-action-sheet');\n document.body.appendChild(actionSheet);\n }\n actionSheet.header = options.promptLabelHeader || 'Photo';\n actionSheet.cancelable = false;\n actionSheet.options = [\n { title: options.promptLabelPhoto || 'From Photos' },\n { title: options.promptLabelPicture || 'Take Picture' },\n ];\n actionSheet.addEventListener('onSelection', async (e) => {\n const selection = e.detail;\n if (selection === 0) {\n this.fileInputExperience(options, resolve);\n }\n else {\n this.cameraExperience(options, resolve, reject);\n }\n });\n }\n else {\n this.cameraExperience(options, resolve, reject);\n }\n });\n }\n async cameraExperience(options, resolve, reject) {\n if (customElements.get('pwa-camera-modal')) {\n const cameraModal = document.createElement('pwa-camera-modal');\n document.body.appendChild(cameraModal);\n try {\n await cameraModal.componentOnReady();\n cameraModal.addEventListener('onPhoto', async (e) => {\n const photo = e.detail;\n if (photo === null) {\n reject(new CapacitorException('User cancelled photos app'));\n }\n else if (photo instanceof Error) {\n reject(photo);\n }\n else {\n resolve(await this._getCameraPhoto(photo, options));\n }\n cameraModal.dismiss();\n document.body.removeChild(cameraModal);\n });\n cameraModal.present();\n }\n catch (e) {\n this.fileInputExperience(options, resolve);\n }\n }\n else {\n console.error(`Unable to load PWA Element 'pwa-camera-modal'. See the docs: https://capacitorjs.com/docs/pwa-elements.`);\n this.fileInputExperience(options, resolve);\n }\n }\n fileInputExperience(options, resolve) {\n let input = document.querySelector('#_capacitor-camera-input');\n const cleanup = () => {\n var _a;\n (_a = input.parentNode) === null || _a === void 0 ? void 0 : _a.removeChild(input);\n };\n if (!input) {\n input = document.createElement('input');\n input.id = '_capacitor-camera-input';\n input.type = 'file';\n input.hidden = true;\n document.body.appendChild(input);\n input.addEventListener('change', (_e) => {\n const file = input.files[0];\n let format = 'jpeg';\n if (file.type === 'image/png') {\n format = 'png';\n }\n else if (file.type === 'image/gif') {\n format = 'gif';\n }\n if (options.resultType === 'dataUrl' ||\n options.resultType === 'base64') {\n const reader = new FileReader();\n reader.addEventListener('load', () => {\n if (options.resultType === 'dataUrl') {\n resolve({\n dataUrl: reader.result,\n format,\n });\n }\n else if (options.resultType === 'base64') {\n const b64 = reader.result.split(',')[1];\n resolve({\n base64String: b64,\n format,\n });\n }\n cleanup();\n });\n reader.readAsDataURL(file);\n }\n else {\n resolve({\n webPath: URL.createObjectURL(file),\n format: format,\n });\n cleanup();\n }\n });\n }\n input.accept = 'image/*';\n input.capture = true;\n if (options.source === CameraSource.Photos ||\n options.source === CameraSource.Prompt) {\n input.removeAttribute('capture');\n }\n else if (options.direction === CameraDirection.Front) {\n input.capture = 'user';\n }\n else if (options.direction === CameraDirection.Rear) {\n input.capture = 'environment';\n }\n input.click();\n }\n _getCameraPhoto(photo, options) {\n return new Promise((resolve, reject) => {\n const reader = new FileReader();\n const format = photo.type.split('/')[1];\n if (options.resultType === 'uri') {\n resolve({\n webPath: URL.createObjectURL(photo),\n format: format,\n });\n }\n else {\n reader.readAsDataURL(photo);\n reader.onloadend = () => {\n const r = reader.result;\n if (options.resultType === 'dataUrl') {\n resolve({\n dataUrl: r,\n format: format,\n });\n }\n else {\n resolve({\n base64String: r.split(',')[1],\n format: format,\n });\n }\n };\n reader.onerror = e => {\n reject(e);\n };\n }\n });\n }\n async checkPermissions() {\n if (typeof navigator === 'undefined' || !navigator.permissions) {\n throw this.unavailable('Permissions API not available in this browser');\n }\n try {\n // https://developer.mozilla.org/en-US/docs/Web/API/Permissions/query\n // the specific permissions that are supported varies among browsers that implement the\n // permissions API, so we need a try/catch in case 'camera' is invalid\n const permission = await window.navigator.permissions.query({\n name: 'camera',\n });\n return {\n camera: permission.state,\n photos: 'granted',\n };\n }\n catch (_a) {\n throw this.unavailable('Camera permissions are not available in this browser');\n }\n }\n async requestPermissions() {\n throw this.unimplemented('Not implemented on web.');\n }\n}\nconst Camera = new CameraWeb();\nexport { Camera };\n//# sourceMappingURL=web.js.map"],"names":["CameraSource","CameraDirection","CameraResultType","Camera","registerPlugin","WebPlugin","CapacitorException"],"mappings":";;;AAAWA,kCAAa;IACxB,CAAC,UAAU,YAAY,EAAE;IACzB,IAAI,YAAY,CAAC,QAAQ,CAAC,GAAG,QAAQ,CAAC;IACtC,IAAI,YAAY,CAAC,QAAQ,CAAC,GAAG,QAAQ,CAAC;IACtC,IAAI,YAAY,CAAC,QAAQ,CAAC,GAAG,QAAQ,CAAC;IACtC,CAAC,EAAEA,oBAAY,KAAKA,oBAAY,GAAG,EAAE,CAAC,CAAC,CAAC;AAC7BC,qCAAgB;IAC3B,CAAC,UAAU,eAAe,EAAE;IAC5B,IAAI,eAAe,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC;IACrC,IAAI,eAAe,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC;IACvC,CAAC,EAAEA,uBAAe,KAAKA,uBAAe,GAAG,EAAE,CAAC,CAAC,CAAC;AACnCC,sCAAiB;IAC5B,CAAC,UAAU,gBAAgB,EAAE;IAC7B,IAAI,gBAAgB,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC;IACpC,IAAI,gBAAgB,CAAC,QAAQ,CAAC,GAAG,QAAQ,CAAC;IAC1C,IAAI,gBAAgB,CAAC,SAAS,CAAC,GAAG,SAAS,CAAC;IAC5C,CAAC,EAAEA,wBAAgB,KAAKA,wBAAgB,GAAG,EAAE,CAAC,CAAC;;ACf1C,UAACC,QAAM,GAAGC,mBAAc,CAAC,QAAQ,EAAE;IACxC,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,I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gB,MAAM,EAAE,SAAS;IACjC,aAAa,CAAC;IACd,SAAS;IACT,QAAQ,OAAO,EAAE,EAAE;IACnB,YAAY,MAAM,IAAI,CAAC,WAAW,CAAC,sDAAsD,CAAC,CAAC;IAC3F,SAAS;IACT,KAAK;IACL,IAAI,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC,CAAC;IAC5D,KAAK;IACL,CAAC;IACD,MAAM,MAAM,GAAG,IAAI,SAAS,EAAE;;;;;;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"plugin.js","sources":["esm/definitions.js","esm/index.js","esm/web.js"],"sourcesContent":["export var CameraSource;\n(function (CameraSource) {\n /**\n * Prompts the user to select either the photo album or take a photo.\n */\n CameraSource[\"Prompt\"] = \"PROMPT\";\n /**\n * Take a new photo using the camera.\n */\n CameraSource[\"Camera\"] = \"CAMERA\";\n /**\n * Pick an existing photo fron the gallery or photo album.\n */\n CameraSource[\"Photos\"] = \"PHOTOS\";\n})(CameraSource || (CameraSource = {}));\nexport var CameraDirection;\n(function (CameraDirection) {\n CameraDirection[\"Rear\"] = \"REAR\";\n CameraDirection[\"Front\"] = \"FRONT\";\n})(CameraDirection || (CameraDirection = {}));\nexport var CameraResultType;\n(function (CameraResultType) {\n CameraResultType[\"Uri\"] = \"uri\";\n CameraResultType[\"Base64\"] = \"base64\";\n CameraResultType[\"DataUrl\"] = \"dataUrl\";\n})(CameraResultType || (CameraResultType = {}));\n//# sourceMappingURL=definitions.js.map","import { registerPlugin } from '@capacitor/core';\nconst Camera = registerPlugin('Camera', {\n web: () => import('./web').then(m => new m.CameraWeb()),\n});\nexport * from './definitions';\nexport { Camera };\n//# sourceMappingURL=index.js.map","import { WebPlugin, CapacitorException } from '@capacitor/core';\nimport { CameraSource, CameraDirection } from './definitions';\nexport class CameraWeb extends WebPlugin {\n async getPhoto(options) {\n // eslint-disable-next-line no-async-promise-executor\n return new Promise(async (resolve, reject) => {\n if (options.webUseInput || options.source === CameraSource.Photos) {\n this.fileInputExperience(options, resolve);\n }\n else if (options.source === CameraSource.Prompt) {\n let actionSheet = document.querySelector('pwa-action-sheet');\n if (!actionSheet) {\n actionSheet = document.createElement('pwa-action-sheet');\n document.body.appendChild(actionSheet);\n }\n actionSheet.header = options.promptLabelHeader || 'Photo';\n actionSheet.cancelable = false;\n actionSheet.options = [\n { title: options.promptLabelPhoto || 'From Photos' },\n { title: options.promptLabelPicture || 'Take Picture' },\n ];\n actionSheet.addEventListener('onSelection', async (e) => {\n const selection = e.detail;\n if (selection === 0) {\n this.fileInputExperience(options, resolve);\n }\n else {\n this.cameraExperience(options, resolve, reject);\n }\n });\n }\n else {\n this.cameraExperience(options, resolve, reject);\n }\n });\n }\n async pickImages(_options) {\n // eslint-disable-next-line no-async-promise-executor\n return new Promise(async (resolve) => {\n this.multipleFileInputExperience(resolve);\n });\n }\n async cameraExperience(options, resolve, reject) {\n if (customElements.get('pwa-camera-modal')) {\n const cameraModal = document.createElement('pwa-camera-modal');\n document.body.appendChild(cameraModal);\n try {\n await cameraModal.componentOnReady();\n cameraModal.addEventListener('onPhoto', async (e) => {\n const photo = e.detail;\n if (photo === null) {\n reject(new CapacitorException('User cancelled photos app'));\n }\n else if (photo instanceof Error) {\n reject(photo);\n }\n else {\n resolve(await this._getCameraPhoto(photo, options));\n }\n cameraModal.dismiss();\n document.body.removeChild(cameraModal);\n });\n cameraModal.present();\n }\n catch (e) {\n this.fileInputExperience(options, resolve);\n }\n }\n else {\n console.error(`Unable to load PWA Element 'pwa-camera-modal'. See the docs: https://capacitorjs.com/docs/pwa-elements.`);\n this.fileInputExperience(options, resolve);\n }\n }\n fileInputExperience(options, resolve) {\n let input = document.querySelector('#_capacitor-camera-input');\n const cleanup = () => {\n var _a;\n (_a = input.parentNode) === null || _a === void 0 ? void 0 : _a.removeChild(input);\n };\n if (!input) {\n input = document.createElement('input');\n input.id = '_capacitor-camera-input';\n input.type = 'file';\n input.hidden = true;\n document.body.appendChild(input);\n input.addEventListener('change', (_e) => {\n const file = input.files[0];\n let format = 'jpeg';\n if (file.type === 'image/png') {\n format = 'png';\n }\n else if (file.type === 'image/gif') {\n format = 'gif';\n }\n if (options.resultType === 'dataUrl' ||\n options.resultType === 'base64') {\n const reader = new FileReader();\n reader.addEventListener('load', () => {\n if (options.resultType === 'dataUrl') {\n resolve({\n dataUrl: reader.result,\n format,\n });\n }\n else if (options.resultType === 'base64') {\n const b64 = reader.result.split(',')[1];\n resolve({\n base64String: b64,\n format,\n });\n }\n cleanup();\n });\n reader.readAsDataURL(file);\n }\n else {\n resolve({\n webPath: URL.createObjectURL(file),\n format: format,\n });\n cleanup();\n }\n });\n }\n input.accept = 'image/*';\n input.capture = true;\n if (options.source === CameraSource.Photos ||\n options.source === CameraSource.Prompt) {\n input.removeAttribute('capture');\n }\n else if (options.direction === CameraDirection.Front) {\n input.capture = 'user';\n }\n else if (options.direction === CameraDirection.Rear) {\n input.capture = 'environment';\n }\n input.click();\n }\n multipleFileInputExperience(resolve) {\n let input = document.querySelector('#_capacitor-camera-input-multiple');\n const cleanup = () => {\n var _a;\n (_a = input.parentNode) === null || _a === void 0 ? void 0 : _a.removeChild(input);\n };\n if (!input) {\n input = document.createElement('input');\n input.id = '_capacitor-camera-input-multiple';\n input.type = 'file';\n input.hidden = true;\n input.multiple = true;\n document.body.appendChild(input);\n input.addEventListener('change', (_e) => {\n const photos = [];\n // eslint-disable-next-line @typescript-eslint/prefer-for-of\n for (let i = 0; i < input.files.length; i++) {\n const file = input.files[i];\n let format = 'jpeg';\n if (file.type === 'image/png') {\n format = 'png';\n }\n else if (file.type === 'image/gif') {\n format = 'gif';\n }\n photos.push({\n webPath: URL.createObjectURL(file),\n format: format,\n });\n }\n resolve({ photos });\n cleanup();\n });\n }\n input.accept = 'image/*';\n input.capture = true;\n input.click();\n }\n _getCameraPhoto(photo, options) {\n return new Promise((resolve, reject) => {\n const reader = new FileReader();\n const format = photo.type.split('/')[1];\n if (options.resultType === 'uri') {\n resolve({\n webPath: URL.createObjectURL(photo),\n format: format,\n saved: false,\n });\n }\n else {\n reader.readAsDataURL(photo);\n reader.onloadend = () => {\n const r = reader.result;\n if (options.resultType === 'dataUrl') {\n resolve({\n dataUrl: r,\n format: format,\n saved: false,\n });\n }\n else {\n resolve({\n base64String: r.split(',')[1],\n format: format,\n saved: false,\n });\n }\n };\n reader.onerror = e => {\n reject(e);\n };\n }\n });\n }\n async checkPermissions() {\n if (typeof navigator === 'undefined' || !navigator.permissions) {\n throw this.unavailable('Permissions API not available in this browser');\n }\n try {\n // https://developer.mozilla.org/en-US/docs/Web/API/Permissions/query\n // the specific permissions that are supported varies among browsers that implement the\n // permissions API, so we need a try/catch in case 'camera' is invalid\n const permission = await window.navigator.permissions.query({\n name: 'camera',\n });\n return {\n camera: permission.state,\n photos: 'granted',\n };\n }\n catch (_a) {\n throw this.unavailable('Camera permissions are not available in this browser');\n }\n }\n async requestPermissions() {\n throw this.unimplemented('Not implemented on web.');\n }\n}\nconst Camera = new CameraWeb();\nexport { Camera };\n//# sourceMappingURL=web.js.map"],"names":["CameraSource","CameraDirection","CameraResultType","Camera","registerPlugin","WebPlugin","CapacitorException"],"mappings":";;;AAAWA,kCAAa;IACxB,CAAC,UAAU,YAAY,EAAE;IACzB;IACA;IACA;IACA,IAAI,YAAY,CAAC,QAAQ,CAAC,GAAG,QAAQ,CAAC;IACtC;IACA;IACA;IACA,IAAI,YAAY,CAAC,QAAQ,CAAC,GAAG,QAAQ,CAAC;IACtC;IACA;IACA;IACA,IAAI,YAAY,CAAC,QAAQ,CAAC,GAAG,QAAQ,CAAC;IACtC,CAAC,EAAEA,oBAAY,KAAKA,oBAAY,GAAG,EAAE,CAAC,CAAC,CAAC;AAC7BC,qCAAgB;IAC3B,CAAC,UAAU,eAAe,EAAE;IAC5B,IAAI,eAAe,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC;IACrC,IAAI,eAAe,CAAC,OAAO,CAAC,GAAG,OAAO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AC;IACf,YAAY,OAAO;IACnB,gBAAgB,MAAM,EAAE,UAAU,CAAC,KAAK;IACxC,gBAAgB,MAAM,EAAE,SAAS;IACjC,aAAa,CAAC;IACd,SAAS;IACT,QAAQ,OAAO,EAAE,EAAE;IACnB,YAAY,MAAM,IAAI,CAAC,WAAW,CAAC,sDAAsD,CAAC,CAAC;IAC3F,SAAS;IACT,KAAK;IACL,IAAI,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC,CAAC;IAC5D,KAAK;IACL,CAAC;IACD,MAAM,MAAM,GAAG,IAAI,SAAS,EAAE;;;;;;;;;;;;;;;;;;"}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
CAP_PLUGIN(CAPCameraPlugin, "Camera",
|
|
5
5
|
CAP_PLUGIN_METHOD(getPhoto, CAPPluginReturnPromise);
|
|
6
|
+
CAP_PLUGIN_METHOD(pickImages, CAPPluginReturnPromise);
|
|
6
7
|
CAP_PLUGIN_METHOD(checkPermissions, CAPPluginReturnPromise);
|
|
7
8
|
CAP_PLUGIN_METHOD(requestPermissions, CAPPluginReturnPromise);
|
|
8
9
|
)
|
|
@@ -9,6 +9,7 @@ public class CameraPlugin: CAPPlugin {
|
|
|
9
9
|
private var settings = CameraSettings()
|
|
10
10
|
private let defaultSource = CameraSource.prompt
|
|
11
11
|
private let defaultDirection = CameraDirection.rear
|
|
12
|
+
private var multiple = false
|
|
12
13
|
|
|
13
14
|
private var imageCounter = 0
|
|
14
15
|
|
|
@@ -66,6 +67,7 @@ public class CameraPlugin: CAPPlugin {
|
|
|
66
67
|
}
|
|
67
68
|
|
|
68
69
|
@objc func getPhoto(_ call: CAPPluginCall) {
|
|
70
|
+
self.multiple = false
|
|
69
71
|
self.call = call
|
|
70
72
|
self.settings = cameraSettings(from: call)
|
|
71
73
|
|
|
@@ -89,6 +91,15 @@ public class CameraPlugin: CAPPlugin {
|
|
|
89
91
|
}
|
|
90
92
|
}
|
|
91
93
|
|
|
94
|
+
@objc func pickImages(_ call: CAPPluginCall) {
|
|
95
|
+
self.multiple = true
|
|
96
|
+
self.call = call
|
|
97
|
+
self.settings = cameraSettings(from: call)
|
|
98
|
+
DispatchQueue.main.async {
|
|
99
|
+
self.showPhotos()
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
92
103
|
private func checkUsageDescriptions() -> String? {
|
|
93
104
|
if let dict = Bundle.main.infoDictionary {
|
|
94
105
|
for key in CameraPropertyListKeys.allCases where dict[key.rawValue] == nil {
|
|
@@ -164,59 +175,145 @@ extension CameraPlugin: PHPickerViewControllerDelegate {
|
|
|
164
175
|
self.call?.reject("User cancelled photos app")
|
|
165
176
|
return
|
|
166
177
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
if let image = reading as? UIImage {
|
|
174
|
-
var asset: PHAsset?
|
|
175
|
-
if let assetId = result.assetIdentifier {
|
|
176
|
-
asset = PHAsset.fetchAssets(withLocalIdentifiers: [assetId], options: nil).firstObject
|
|
177
|
-
}
|
|
178
|
-
if let processedImage = self?.processedImage(from: image, with: asset?.imageData) {
|
|
179
|
-
self?.returnProcessedImage(processedImage)
|
|
178
|
+
if multiple {
|
|
179
|
+
var images: [ProcessedImage] = []
|
|
180
|
+
var processedCount = 0
|
|
181
|
+
for img in results {
|
|
182
|
+
guard img.itemProvider.canLoadObject(ofClass: UIImage.self) else {
|
|
183
|
+
self.call?.reject("Error loading image")
|
|
180
184
|
return
|
|
181
185
|
}
|
|
186
|
+
// extract the image
|
|
187
|
+
img.itemProvider.loadObject(ofClass: UIImage.self) { [weak self] (reading, _) in
|
|
188
|
+
if let image = reading as? UIImage {
|
|
189
|
+
var asset: PHAsset?
|
|
190
|
+
if let assetId = result.assetIdentifier {
|
|
191
|
+
asset = PHAsset.fetchAssets(withLocalIdentifiers: [assetId], options: nil).firstObject
|
|
192
|
+
}
|
|
193
|
+
if let processedImage = self?.processedImage(from: image, with: asset?.imageData) {
|
|
194
|
+
images.append(processedImage)
|
|
195
|
+
}
|
|
196
|
+
processedCount += 1
|
|
197
|
+
if processedCount == results.count {
|
|
198
|
+
self?.returnImages(images)
|
|
199
|
+
}
|
|
200
|
+
} else {
|
|
201
|
+
self?.call?.reject("Error loading image")
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
} else {
|
|
207
|
+
guard result.itemProvider.canLoadObject(ofClass: UIImage.self) else {
|
|
208
|
+
self.call?.reject("Error loading image")
|
|
209
|
+
return
|
|
210
|
+
}
|
|
211
|
+
// extract the image
|
|
212
|
+
result.itemProvider.loadObject(ofClass: UIImage.self) { [weak self] (reading, _) in
|
|
213
|
+
if let image = reading as? UIImage {
|
|
214
|
+
var asset: PHAsset?
|
|
215
|
+
if let assetId = result.assetIdentifier {
|
|
216
|
+
asset = PHAsset.fetchAssets(withLocalIdentifiers: [assetId], options: nil).firstObject
|
|
217
|
+
}
|
|
218
|
+
if let processedImage = self?.processedImage(from: image, with: asset?.imageData) {
|
|
219
|
+
self?.returnProcessedImage(processedImage)
|
|
220
|
+
return
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
self?.call?.reject("Error loading image")
|
|
182
224
|
}
|
|
183
|
-
self?.call?.reject("Error loading image")
|
|
184
225
|
}
|
|
226
|
+
|
|
185
227
|
}
|
|
186
228
|
}
|
|
187
229
|
|
|
188
230
|
private extension CameraPlugin {
|
|
189
|
-
func
|
|
231
|
+
func returnImage(_ processedImage: ProcessedImage, isSaved: Bool) {
|
|
190
232
|
guard let jpeg = processedImage.generateJPEG(with: settings.jpegQuality) else {
|
|
191
233
|
self.call?.reject("Unable to convert image to jpeg")
|
|
192
234
|
return
|
|
193
235
|
}
|
|
194
236
|
|
|
195
|
-
if settings.resultType == CameraResultType.
|
|
237
|
+
if settings.resultType == CameraResultType.uri || multiple {
|
|
238
|
+
guard let fileURL = try? saveTemporaryImage(jpeg),
|
|
239
|
+
let webURL = bridge?.portablePath(fromLocalURL: fileURL) else {
|
|
240
|
+
call?.reject("Unable to get portable path to file")
|
|
241
|
+
return
|
|
242
|
+
}
|
|
243
|
+
if self.multiple {
|
|
244
|
+
call?.resolve([
|
|
245
|
+
"photos": [[
|
|
246
|
+
"path": fileURL.absoluteString,
|
|
247
|
+
"exif": processedImage.exifData,
|
|
248
|
+
"webPath": webURL.absoluteString,
|
|
249
|
+
"format": "jpeg"
|
|
250
|
+
]]
|
|
251
|
+
])
|
|
252
|
+
return
|
|
253
|
+
}
|
|
196
254
|
call?.resolve([
|
|
255
|
+
"path": fileURL.absoluteString,
|
|
256
|
+
"exif": processedImage.exifData,
|
|
257
|
+
"webPath": webURL.absoluteString,
|
|
258
|
+
"format": "jpeg",
|
|
259
|
+
"saved": isSaved
|
|
260
|
+
])
|
|
261
|
+
} else if settings.resultType == CameraResultType.base64 {
|
|
262
|
+
self.call?.resolve([
|
|
197
263
|
"base64String": jpeg.base64EncodedString(),
|
|
198
264
|
"exif": processedImage.exifData,
|
|
199
|
-
"format": "jpeg"
|
|
265
|
+
"format": "jpeg",
|
|
266
|
+
"saved": isSaved
|
|
200
267
|
])
|
|
201
268
|
} else if settings.resultType == CameraResultType.dataURL {
|
|
202
269
|
call?.resolve([
|
|
203
270
|
"dataUrl": "data:image/jpeg;base64," + jpeg.base64EncodedString(),
|
|
204
271
|
"exif": processedImage.exifData,
|
|
205
|
-
"format": "jpeg"
|
|
272
|
+
"format": "jpeg",
|
|
273
|
+
"saved": isSaved
|
|
206
274
|
])
|
|
207
|
-
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
func returnImages(_ processedImages: [ProcessedImage]) {
|
|
279
|
+
var photos: [PluginCallResultData] = []
|
|
280
|
+
for processedImage in processedImages {
|
|
281
|
+
guard let jpeg = processedImage.generateJPEG(with: settings.jpegQuality) else {
|
|
282
|
+
self.call?.reject("Unable to convert image to jpeg")
|
|
283
|
+
return
|
|
284
|
+
}
|
|
285
|
+
|
|
208
286
|
guard let fileURL = try? saveTemporaryImage(jpeg),
|
|
209
287
|
let webURL = bridge?.portablePath(fromLocalURL: fileURL) else {
|
|
210
288
|
call?.reject("Unable to get portable path to file")
|
|
211
289
|
return
|
|
212
290
|
}
|
|
213
|
-
|
|
291
|
+
|
|
292
|
+
photos.append([
|
|
214
293
|
"path": fileURL.absoluteString,
|
|
215
294
|
"exif": processedImage.exifData,
|
|
216
295
|
"webPath": webURL.absoluteString,
|
|
217
296
|
"format": "jpeg"
|
|
218
297
|
])
|
|
219
298
|
}
|
|
299
|
+
call?.resolve([
|
|
300
|
+
"photos": photos
|
|
301
|
+
])
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
func returnProcessedImage(_ processedImage: ProcessedImage) {
|
|
305
|
+
// conditionally save the image
|
|
306
|
+
if settings.saveToGallery && (processedImage.flags.contains(.edited) == true || processedImage.flags.contains(.gallery) == false) {
|
|
307
|
+
_ = ImageSaver(image: processedImage.image) { error in
|
|
308
|
+
var isSaved = false
|
|
309
|
+
if error == nil {
|
|
310
|
+
isSaved = true
|
|
311
|
+
}
|
|
312
|
+
self.returnImage(processedImage, isSaved: isSaved)
|
|
313
|
+
}
|
|
314
|
+
} else {
|
|
315
|
+
self.returnImage(processedImage, isSaved: false)
|
|
316
|
+
}
|
|
220
317
|
}
|
|
221
318
|
|
|
222
319
|
func showPrompt() {
|
|
@@ -332,7 +429,7 @@ private extension CameraPlugin {
|
|
|
332
429
|
@available(iOS 14, *)
|
|
333
430
|
func presentPhotoPicker() {
|
|
334
431
|
var configuration = PHPickerConfiguration(photoLibrary: PHPhotoLibrary.shared())
|
|
335
|
-
configuration.selectionLimit = 1
|
|
432
|
+
configuration.selectionLimit = self.multiple ? (self.call?.getInt("limit") ?? 0) : 1
|
|
336
433
|
configuration.filter = .images
|
|
337
434
|
let picker = PHPickerViewController(configuration: configuration)
|
|
338
435
|
picker.delegate = self
|
|
@@ -380,11 +477,8 @@ private extension CameraPlugin {
|
|
|
380
477
|
metadata = asset.imageData
|
|
381
478
|
}
|
|
382
479
|
// get the result
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
if settings.saveToGallery && (flags.contains(.edited) == true || flags.contains(.gallery) == false) {
|
|
386
|
-
UIImageWriteToSavedPhotosAlbum(result.image, nil, nil, nil)
|
|
387
|
-
}
|
|
480
|
+
var result = processedImage(from: image, with: metadata)
|
|
481
|
+
result.flags = flags
|
|
388
482
|
return result
|
|
389
483
|
}
|
|
390
484
|
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import UIKit
|
|
2
|
+
|
|
3
|
+
class ImageSaver: NSObject {
|
|
4
|
+
|
|
5
|
+
var onResult: ((Error?) -> Void) = {_ in }
|
|
6
|
+
|
|
7
|
+
init(image: UIImage, onResult:@escaping ((Error?) -> Void)) {
|
|
8
|
+
self.onResult = onResult
|
|
9
|
+
super.init()
|
|
10
|
+
UIImageWriteToSavedPhotosAlbum(image, self, #selector(saveResult), nil)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
@objc func saveResult(_ image: UIImage, didFinishSavingWithError error: Error?, contextInfo: UnsafeRawPointer) {
|
|
14
|
+
if let error = error {
|
|
15
|
+
onResult(error)
|
|
16
|
+
} else {
|
|
17
|
+
onResult(nil)
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capacitor/camera",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "The Camera API provides the ability to take a photo with the camera or choose an existing one from the photo album.",
|
|
5
5
|
"main": "dist/plugin.cjs.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"verify:android": "cd android && ./gradlew clean build test && cd ..",
|
|
34
34
|
"verify:web": "npm run build",
|
|
35
35
|
"lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
|
|
36
|
-
"fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint --
|
|
36
|
+
"fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --fix --format",
|
|
37
37
|
"eslint": "eslint . --ext ts",
|
|
38
38
|
"prettier": "prettier \"**/*.{css,html,ts,js,java}\"",
|
|
39
39
|
"swiftlint": "node-swiftlint",
|
|
@@ -42,13 +42,12 @@
|
|
|
42
42
|
"clean": "rimraf ./dist",
|
|
43
43
|
"watch": "tsc --watch",
|
|
44
44
|
"prepublishOnly": "npm run build",
|
|
45
|
-
"postpublish": "npm run publish:cocoapod",
|
|
46
45
|
"publish:cocoapod": "pod trunk push ./CapacitorCamera.podspec --allow-warnings"
|
|
47
46
|
},
|
|
48
47
|
"devDependencies": {
|
|
49
48
|
"@capacitor/android": "^3.0.0",
|
|
50
49
|
"@capacitor/core": "^3.0.0",
|
|
51
|
-
"@capacitor/docgen": "0.0.
|
|
50
|
+
"@capacitor/docgen": "0.0.18",
|
|
52
51
|
"@capacitor/ios": "^3.0.0",
|
|
53
52
|
"@ionic/eslint-config": "^0.3.0",
|
|
54
53
|
"@ionic/prettier-config": "~1.0.1",
|
|
@@ -80,5 +79,5 @@
|
|
|
80
79
|
"publishConfig": {
|
|
81
80
|
"access": "public"
|
|
82
81
|
},
|
|
83
|
-
"gitHead": "
|
|
82
|
+
"gitHead": "64df93225736e9dfad336562f5e53e5a2243052b"
|
|
84
83
|
}
|